Important: Please read the Qt Code of Conduct -

OpenGL invalid operation after Qt 5.4.1 upgrade to 5.7.0 (glGetError 1282)

  • Hi,

    I work on a project which is use Qt 5.4.1 with OpenGL, here is the installer which i installed earlier:

    A few days ago, we have done an upgrade from Qt 5.4.1 to Qt 5.7.0, so i installed this package:

    On this project, we use OpenGL context too, which is works perfectly under Qt 5.4.1.
    After upgade to Qt 5.7.0, we got unexpected errors.
    For debugging i use glGetError() method which is returned value of 1282, which means "invalid operation".
    Someone has encountered a similar problem?

    So everything is the same, the IDE, the project, the building process, OpenGL driver, except the version of Qt ...
    I did the required settings, i.e. setting properly environment variables, set the Qt version in Visual Studio ...

    Thanks in advance,

  • Lifetime Qt Champion

    Hi and welcome to devnet,

    WARNING: I'm no OpenGL expert, just did small stuff with it.
    However, from what I know: are you writing any shader in your application ? If so are you checking that they still compile successfully ?

  • I met similar problem.
    In my case, the problem is caused by NULL opengl context in QQuickView's scene graph.
    After scene graph initialized successfully, the QOpenGLContext::currentContext() is still NULL.
    With NULL openglContext(), the gl functions failed and get error GL_INVALID_OPERATION.

    My solution is to create an opengl context to enable the gl functions. Make sure you share the context if you use the initialized textures, vertex buffers, etc. in other renderer with default qt provided opengl context.

    Actually the opengl context behaves quite different in Qt 5.7.0 than Qt 5.4.1. As far as I understand from Qt Document, the multiple QQuickWindow instance should use the same opengl context. And in Qt 5.4.1, it is the case. But in Qt 5.7.0, it seems that each QQuickWindow has its own opengl context, thus I got the error "Cannot make QOpenGLContext current in a different thread". I hope some one can answer my question.

  • This post is deleted!

  • Hi guys, sorry for my delay.

    So the first is, big thanks for your reply.

    SGaist: I do not use any shader.

    Here is a little code snippet, which is the core of problem (i think).
    So, i use a valid shared QOpenGLContext pointer named sharedContext;
    After that i create a QOpenGLContext (glContext) and a QOffscreenSurface (glSurface) pointer too.
    After that i invoke the setShareContext() method of previous QOpenGLContext pointer (glContext) with parameter of sharedContext.
    You will see it in the first four lines.

    if (sharedContext) {
       QOpenGLContext glContext = new QOpenGLContext();
       QOffscreenSurface glSurface = new QOffscreenSurface;
       glContext->create(); // true
       glContext->makeCurrent(glSurface); // true
       bool isValid = glContext->isValid(); // true
       auto error = glContext->functions()->glGetError(); // 0
       // isValid is true and error is 0, so everything is ?OK?
       auto currentContext = wglGetCurrentContext(); // nullptr
       auto currentDC = wglGetCurrentDC(); // nullptr
       // but currentContext and currentDC is null

    I do not understand why currentContext and currentDC is null, namely variable of isValid set as true and variable of error set as 0, so everything is OK at least in appearance.

    What could be the problem?

  • After glContext->setShareContext(sharedContext);
    You need to call glContext->create();
    to create this opengl context.

  • Thanks for your reply @lilyofvalley.
    Invoke of create() is already in code. You can see it in the main post.

    glContext->create(); // true

    But fortunately turned out, there is an other problem which causes everything.
    You can read it in this post: Can not set renderable type from OpenGLES to OpenGL in Qt 5.7.0

    Have you got any idea about it?

  • Hi,

    I think i found the solution. Qt::AA_UseDesktopOpenGL and Qt::AA_ShareOpenGLContexts attributes solved my problem.

  • This post is deleted!

Log in to reply