1

My goal is to be able to use a joystick inside of Qt (to add a piloting task to an existing Qt app) Note : Qt 5.4 // SFML 2.2 (running on CentOS7)

In order to do so, I used the tutorial on the sfml website explaining how to insert an sfml window inside of a Qt widget. That tutorial ( http://www.sfml-dev.org/tutorials/1.6/graphics-qt.php ) being too old, I had to change some things in order to update it for sfml 2.2.

However things do not work as intended and while it does compile, it seems to be unable to create the sfml window from the winid and end up crashing

Here is the part of code corresponding to the window creation :

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;
    }
}

And here is the output

Bla
Blabla
35651593
Blablabla

...and crash

As you see it seems to have no trouble obtaining the window handle but can't create the sfml renderwindow from it Note that there is a static_cast for the handle that isn't there in the tutorial. Different questions suggested putting a reinterpret_cast but then it gives me this error

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());

Is there a way to solve this problem ? Or are just SFML & Qt fated to never work together anymore ? Thank you for your help

Glypwota
  • 11
  • 2

0 Answers0