How to render QOpenGLWidget content from secondary thread?



  • Hi all

    I have a situation where the main GUI loop is continuosly locked by thirty part code but I would to show an animation keep running without lags. Using QML BusyIndicator control I noted it keep moving also if GUI loop is locked. Checking the sources I knew it have some way to render OpenGL content from different thread. I'm looking for same whay but on C++ side. Is possible to find some example (GL Hypnotizer) but referring to Qt version 4.8. On new 5 version something is changed and these example can not work anymore (GLWidget has been deprecated in favour of QOpenGLWidget that work in a diferent mode). I found some explanation around but that always need the main GUI to notify some lock/unlock state of OpenGL frame buffer and is not what I need. I need a way to render and update the QOpenGLWidget content totally from a secondary thread without any intereaction from main GUI loop.

    Someone can give me help or point to some working example in Qt 5?
    Thank you



  • Hi @Suppaman

    According to qt doc the main thread is always dedicated to GUI

    http://doc.qt.io/qt-5/thread-basics.html#gui-thread-and-worker-thread

    In this link , you can read:

    "All widgets and several related classes, for example QPixmap, don't work in secondary threads. A secondary thread is commonly referred to as a "worker thread" because it is used to offload processing work from the main thread."

    I think that the real problem is that you are locking the GUI thread (which should never happen),

    Maybe you should use worker thread for the computations that are locking your main thread,



  • Hi

    As already wrote QML BusyIndicator can make such operation to keep animation running also if main GUI thread is locked. The info you reported is correct but OpenGL from version 2.0 and above allow to render from a secondary thread that what I want to make is possibile (again only using OpenGL). My problem is I still don't understand how to make it using Qt 5...


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.