Important: Please read the Qt Code of Conduct -

QOpenGLContext fail makeCurrent(surface)

  • Hi guys,

    i want to create a UI with QT for my existed OpenGL programm. So i created a QWindow with OpenGLSurface and also an OpenGLContext. Everything went well, but the call mOpenGLContext->makeCurrent(this) always fails. Anybody know why? in this case: "this" is an instance of QWindow with OpenGLSurface:

     OpenGLWindow::OpenGLWindow( QWindow *parent /*= 0*/ )
    void OpenGLWindow::createOpenGLContext( )
        mOpenGLContext = new QOpenGLContext(this);
        QSurfaceFormat format = requestedFormat();
        if(mOpenGLContext->isValid() && mOpenGLContext->makeCurrent(this)){
            emit runCS();
             msgWindow.setText("Error: can not create OpenGLContext:\n");

    NOTE: Using QOpenGLWindow the programm appears with blank window for 2-5 seconds. It seems the initializeGL method is called after a while. That´s why i want to create my own QOpenGLContext.

    Thanks in advance for help,

  • Moderators

    Is the window shown before you call createOpenGLContext()? If not then the underlying surface might not be created yet. In that case you need to call create() manually before making a context current on that surface.

  • @Chris-Kawa
    Thank you Chris, but i already called create().

  • Moderators

    Just to clarify: you called create() on the context. I meant to call create() on the window. Did you do that as well?

  • @Chris-Kawa
    Ahh thanks. It solves my problem. You are the man of the day!

  • Any more information on what happens after the blank window appears? What does 'always fails' mean ?
    For instance, do you get a SEG Fault, bus err, are any error messages thrown? Does the application completely stop or freeze or is it just a blank rendering area ?

    • Vince

  • @Vince-Golubic

    I mentioned 2 methods to create an area for drawing OpenGL directly.
    1. Method: Create QWindow and QOpenGLContext your own. Here i forgot to call manually QWindow::create().
    2. Method: Just inherit QOpenGLWindow and call your own draw method in paintGL(). With this method my programm shows a blank window for about 2-5 seconds, then openGL things appear. It seems the initializeGL() method is called far too late. If you guys have any idea how to speed up it, i would very appreciate to know.

  • Moderators

    Looking at the source code of QOpenGLWindow the context creation happens on the first draw request. I don't see a way to force it earlier or set a ready made context, so this will always produce a visual gap. It's not that bad on my machine (0.5s to 1s) but it's noticeable.
    I guess you could file a bug report on this.

Log in to reply