I am using two QGLWidgets. One for loading textures and one for rendering, but it doesn't work.
I used the following explanation from http://blog.qt.digia.com/blog/2011/06/03/threaded-opengl-in-4-8/
Downloading a texture theme Loading many (or large) textures is usually an expensive operation due to the amount of data being transferred to the GPU. Again, this is one of those operations that can unnecessarily block the main thread. In 4.8, you can solve this problem by creating a couple of common QGLWidgets. One of the widgets runs in a separate thread, but is never displayed on the screen. The main thread informs the loading stream that the images are loading, and the loading stream simply calls bindTexture () on each of these images, and then notifies the main stream when each of them is complete so that it can be drawn on the screen.
It works fine with Qt 4.8 with MinGW, but now I am using Qt 5.1 with MSVC. I get an error when I want to make the widget in the stream current:
Cannot include QOpenGLContext in another thread
I understand the error, but how can I fix it. When I do not install the current widget, I canโt load the textures (hang in the bindTexture () function). I also wonder why it works with my old version of QT. When an error appears, I can click โignore errorโ and the program will load the textures anyway.
Here is a sample code:
Texture loading:
GLContext::GLContext(QWidget *parent, QGLWidget *myDisplayWidget) : QGLWidget(parent,myDisplayWidget) { }
...
GLContext* myTextureWidget = new GLContext(this,myDisplayWidget);
...
void TextureLoadingThread::run() { makeCurrent();
EDIT:
When I move the myTextureWidget context to a stream, it works, but then I get a makeCurrent error from the API when building the GUI (the stack trace specified in the QLineEdit :: setPlaceHolderText function in QT5Widgetsd). When I move myTextureWidget to the stream a few seconds after showing the main window, everything works fine. But how can I find out when qt finished all GUI building materials? I am drawing a GUI in a QGraphicsView with a QGLWidget viewport.
myTextureWidget->context()->moveToThread(myTextureLoadingThread);