Search code examples
qtopenglqt4qglwidgetqt4.8

what does "QGLContext::makeCurrent() : wglMakeCurrent failed: The operation completed successfully" mean?


I am trying to make a multi threaded Qt Application that uses QGLWidgets and I keep getting this error.(I am trying to paint from another thread using QPainter)

And it also looks like I have a huge memory leak because of it.

The error is "QGLContext::makeCurrent() : wglMakeCurrent failed: The operation completed successfully"


Solution

  • I believe this is related to a rather old issue from the Qt mailing list as described here. In short, if the thread calling makeCurrent() does not equal the thread where the device context was retrieved, GetDC() is called. As outlined in the linked thread, the problem is that ReleaseDC() is not called accordingly, resulting in a handle leak, and triggering Windows to return NULL in the call to GetDC() at some point, which makes wglMakeCurrent() fail. I don't know, however, why GetLastError() claims "The operation completed successfully" in this case.