QSFMLCanvas没有在Qt5.4 SFML2.2上工作

时间:2015-05-20 15:10:00

标签: c++ qt qt-creator sfml joystick

我的目标是能够在Qt中使用操纵杆(将驾驶任务添加到现有的Qt应用程序中) 注意:Qt 5.4 // SFML 2.2(在CentOS7上运行)

为了做到这一点,我在sfml网站上使用了教程,解释了如何在Qt小部件中插入sfml窗口。该教程(http://www.sfml-dev.org/tutorials/1.6/graphics-qt.php)太旧了,我不得不改变一些东西,以便为sfml 2.2更新它。

然而事情并没有按预期工作,而且在编译时,它似乎无法从winid创建sfml窗口并最终崩溃

以下是与窗口创建相对应的代码部分:

void QSFMLCanvas::showEvent(QShowEvent*)
{
    if (!myInitialized)
    {
        std::cout << "Bla" << std::endl;
        // Under X11, we need to flush the commands sent to the server to ensure that
        // SFML will get an updated view of the windows
        #ifdef Q_WS_X11
            XFlush(QX11Info::display());
        #endif

        std::cout << "Blabla" << std::endl;

        // Create the SFML window with the widget handle
        sf::WindowHandle HANDLE;
        HANDLE = static_cast<sf::WindowHandle>(winId());
        std::cout << HANDLE << std::endl;
        std::cout << "Blablabla" << std::endl;
        sf::RenderWindow::create(HANDLE);
        std::cout << "Blablablabla" << std::endl;

        // Let the derived class do its specific stuff
        OnInit();

        // Setup the timer to trigger a refresh at specified framerate
        connect(&myTimer, SIGNAL(timeout()), this, SLOT(repaint()));
        myTimer.start();
        myInitialized = true;
    }
}

这是输出

Bla
Blabla
35651593
Blablabla

......然后崩溃

如您所见,获取窗口句柄似乎没有问题,但无法从中创建sfml渲染窗口 请注意,教程中没有针对句柄的static_cast。不同的问题建议放一个reinterpret_cast但是它给了我这个错误

QSFMLCanvas.cpp: In member function ‘virtual void QSFMLCanvas::showEvent(QShowEvent*)’:
QSFMLCanvas.cpp:48:60: erreur: invalid cast from type ‘WId {aka long long unsigned int}’ to type ‘sf::WindowHandle {aka long unsigned int}’
         HANDLE = reinterpret_cast<sf::WindowHandle>(winId());

有没有办法解决这个问题?或者只是SFML&amp; Qt注定永远不再合作? 谢谢你的帮助

0 个答案:

没有答案