Important: Please read the Qt Code of Conduct -

WGL Window on non-GUI thread

  • Hi guys,

    I started out trying to create an OpenGL render window on a non-GUI thread using QT's OpenGL resources as explained in this thread:

    My reason for attempting to do this is because my GUI thread is pretty busy with a lot of events and widgets and this causes stuttering and dropped frames when I use a QWindow.

    At the moment, I've gotten as far as creating a native WGL context / window which I used to create a QOpenGLContext:
    Here is a github link to the project:

    void OpenGLNativeRenderWindow::showNative()
        //Create native window and context
        //Allocate memory for the context object and prepare to create it
        openGLContext = new QOpenGLContext(this);
        QWGLNativeContext nativeContext(hglrc,hwnd);
        //Make sure the context is created & is sharing resources with the shared context
        bool contextCreated = openGLContext->create();
            bool sharing = QOpenGLContext::areSharing(openGLContext,sharedOpenGLContext);
        //Resize / show window
        visible = !ShowWindow(hwnd,SW_SHOWNORMAL);

    All the resources, including the native window, are created without issues and I'm able to make the QT context current on a separate thread and OpenGL rendering also produces no errors but Hello Triangle doesn't render on my window. It seems that the native WGL context and the QT context are still separate entities.

    If I make direct WGL calls to make the context current / swap buffers, I seem to be able to make OpenGL calls on the native window but it still seems I can't access the resources the QT context renders (e.g. FBO output texture).

    Any thoughts on what could be wrong?