PDA

View Full Version : Threaded QGLWidged -> QGLContext::makeCurrent(): Failed.



beetleskin
2nd February 2011, 14:27
Hi,

I'm working on a project in which I have to draw a QGLWidget with constant 60fps. I addition, some textures within the GL-context are changing frequently.

I want to separate that to tasks into two threads, one for the fast-refreshing GL-context and one for texture update and other things. The last one should be the main QApplication thread. I had two approaches of implementing that structure but both result in the error message: QGLContext::makeCurrent(): Failed.

With the first try I basically followed this tutorial:
http://doc.trolltech.com/qq/qq06-glimpsing.html#writingmultithreadedglapplications

The second one was to wrap the QGLWidget in a thread, constantly calling the widgets updateGL() function.

I didn't come as far as safely updating the textures as I get the error right after initialization.

I'm workin on Ubuntu, so I called XInitThreads() first.

Does someone have an idea why the makeCurrent fails? Or even a better workaround for the general task?

Thanks.

sampats
7th May 2011, 12:17
Hi beetleskin
I'm trying to do the same thing and get the same error related to QGLContext::makeCurrent() failed. Have you been able to resolve this problem? If so please share it with me cos that would really help me.

NeilMonday
20th June 2011, 21:55
I too am in the same boat. Any help is greatly appreciated.

stampede
20th June 2011, 22:27
If I understand correctly, you want to use QWidget-based class outside main GUI thread. Well, I think its not a good idea:

Although QObject is reentrant, the GUI classes, notably QWidget and all its subclasses, are not reentrant. They can only be used from the main thread.
Next thing:

two threads, one for the fast-refreshing GL-context and one for texture update and other things. The last one should be the main QApplication thread.
I think that the first one should be in main thread, create a separate thread to play with the textures and pass the result to main thread for display.
Let the main thread handle the display, gl-context refreshing or whatever. Manipulate the image data in other thread, if it needs some heavy processing, and send processed images for display to gui thread.