⚠️ Forum Maintenance: Feb 6th, 8am - 14pm (UTC+2)

glGetString(GL_VERSION) returns NULL

  • Hello,

    I am trying to port a Qt5.1 application to Qt5.5. I noticed that QGLWidget should not be used anymore and I replaced it with QOpenGLWidget. All works fine when I launch the application from Qt creator. But when I launch it via command line (I paid attention to have all required Qt libraries present in the same folder) my call to glGetString(GL_VERSION) always returns NULL. This is a mystery to me.

    How I do things:
    I create a QOpenGLWidget and set it as the central widget in a QMainWindow. Then I make the window visible and resize it. During the resize operation, resizeEvent is called, which also calls initializeGL. And in initializeGL, I make the context current, then call glGetString.

    How come things work fine when launched from QtCreator, but fails from command-line?

    In my application directory, I put all required Qt libraries. Basically (and all, to be sure):

    • All files in Qt5.5.0/5.5/mingw492_32/bin
    • All files and folders in Qt5.5.0/5.5/mingw492_32/plugins

    My project file contains (running on Windows 8):

    QT += network opengl printsupport
    LIBS += -lopengl32

    Any help is greatly appreciated.

  • Have you tried using the windeployqt tool instead of copying everything manually?

  • Thank you Paul,

    I have tried that, but the result is the same..

  • You can try comparing the path in QT Creator environment under Projects with the path in the command shell and see if anything is different. That might point you in the right direction. Can you build the application from the command shell you are using?

  • Thanks again Paul.

    That didn't help unfortunately. But I discovered something that could give a clue as to what is going wrong:

    So I called this time the glGetString openGl function twice, once directly (as is done in the whole application), and once via QOpenGLFunctions:

    const char* gl_version=(const char*)(glGetString(GL_VERSION));
    printf("called directly: glVersion: %s\n",gl_version);
    QOpenGLFunctions* f=openglWidget->context()->functions();
    gl_version=(const char*)(f->glGetString(GL_VERSION));
    printf("called via QOpenGLFunctions: glVersion: %s\n",gl_version);

    When I start the application via QtCreator, I get:

    called directly: glVersion: 4.3.0
    called via QOpenGLFunctions: glVersion: 4.3.0

    When I start the application via the command line, for the ready-to-ship application, I get:

    called directly: glVersion: (null)
    called via QOpenGLFunctions: glVersion: OpenGL ES 2.0 (ANGLE 2.1.99f075dade7c)

    I know it is best to call all gl functions via the second method, but the application is very large and openGl code is all over the place. So it will take quite some time to refactor things. But until then, I wish to be able to continue calling openGl functions directly.

    Do I need to change a setting in order to be able to do it?
    For information, that application is only deployed on desktops (Windows, Max and Linux)


  • I can also confirm that the problem is not directly linked to QOpenGLWidget: when still using QGLWidget, I have the same result.

    When I had to port the application from Qt 5.1 to Qt5.5 I had to add following line in the Qt project file, which wasn't needed in Qt 5.1:

    LIBS += -lopengl32

    Without above line, Qt5.5 doesn't recognize the OpenGl standard functions (such as glBegin, etc.)
    Might this be another clue?

  • Well, it is reporting different versions in the different environments. I would try running process explorer and see what dlls are being used for each environment.

  • Ok, so I used the process explorer, and noticed that the deployed application (i.e. the one not launched via QtCreator) is has libGLESV2.dll loaded. How come? I do not need GL ES, nor do I want it (my application still uses old OpenGL fixed-pipeline code).

    Searching the internet for libGLESV2.dll, I found out that libGLESv2.dll is distributed by Mozilla Foundation and used by Firefox 9.0.1 application. How come my application is using it? How can I prevent this?


  • Lifetime Qt Champion


    IIRC, Qt on Windows loads at runtime either the OpenGL or ANGLE backend depending on what you have available on the machine where you run the application. You might be seeing that happening.

  • Thanks Samuel.

    I basically don't need OpenGL ES, I am just using old fixed-pipeline OpenGl commands (probably not much more than OpenGl 2.0). What are my options?

    I also tried to deploy the application by specifying that I don't want the ANGLE library (--no-angle), but then, I get a bunch of messages (then a crash) like:

    Failed to load libEGL.dll ...
    static QWindowsEGLStaticContext* QWindowsEGLStaticCOntext::create(QWindowsOpenGLTester::Renderers): Failed to load and resolve libEGL functions


  • Lifetime Qt Champion

    How are you doing the deployment ?

  • Sorry for the delay..
    I deploy the application (which is a library (loaded by an executable)) with:

    windeployqt --no-angle directoryToMyDll\myDll.dll

    It then tells me:

    To be deployed: Qt5Core Qt5Gui Qt5Network Qt5OpenGL Qt5Svg Qt5Widgets


  • Lifetime Qt Champion

    I'm not sure I'm following you, you have a Qt application + library to deploy ?

  • I have the same issue :

    I force Qt to use OpenGL instead of Angle and it's not enough, I also link statically openGL library.
    The openGL context is necessary created cause, we call glGetString after the display of the splash screen of the application.

    I want to check the QOpenGLContext::currentContext() ptr, but I can't make it build, the QOpenGLContext header doesn't provide the class definition.

  • I have prepared a minimalistic application that illustrates the problem.

    The minimalistic application will build a QMainWindow, and set a QOpenGlWidget-derived widget as the central element. Then, in that widget, in the initializeGL function I check the GL_VERSION. When I run it from QtCreator, it works fine. When I deploy the application and I run it from the command line, it fails with the glGetString function.
    Here the minimalistic application:

    Project file:

    QT			+=	widgets opengl
    LIBS		+=	-lopengl32
    QT			+=	core
    HEADERS		=	myGlWidgetClass.h
    SOURCES		=	myGlWidgetClass.cpp \

    The QOpenGLWidget-derived class (header):

    #include <QOpenGLWidget>
    class MyGlWidgetClass : public QOpenGLWidget
    	MyGlWidgetClass(QWidget *parent = 0);
    	void initializeGL();

    The QOpenGLWidget-derived class (implementation):

    #include "myGlWidgetClass.h"
    MyGlWidgetClass::MyGlWidgetClass(QWidget *parent) : QOpenGLWidget(parent)
    void MyGlWidgetClass::initializeGL()
    	const char* gl_version=(const char*)(glGetString(GL_VERSION));
    	if (gl_version==NULL)

    And the application main code:

    #include <QApplication>
    #include <QMainWindow>
    #include "myGlWidgetClass.h"
    int main(int argc, char *argv[])
    	QApplication app(argc, argv);
    	QMainWindow myMainWindow;
    	myMainWindow.setCentralWidget(new MyGlWidgetClass(&myMainWindow));
    	return app.exec();

    I also have to mention again that this problem happens with Qt 5.5, but not with Qt5.1.1 (both on Windows 8.1). (with Qt5.1.1, simply replace QOpenGLWidget with QGLWidget (since QOpenGLWidget is new since Qt5.4))


  • Hello again,

    for your info: I am able to invert the problem with following code before building the application:


    With invert, I mean that with above call, I can run my application from the command line, but not from QtCreator anymore (only a black screen in that case, not even the toolbar buttons are visible anymore)

    Details and a demo application that illustrates the problem can be found here


Log in to reply