QGLWidget ceased to work on Windows in Qt 5.7?



  • The following application works well with Qt 5.5, but only black screen with 5.7. What gives? My OGL application is entirely broken and I traced the problem back to this primitive example after 3 hours of banging my head on the wall.

    #include <QApplication>
    #include <QGLWidget>
    #include <QMainWindow>
    
    class GlTestWidget : public QGLWidget
    {
    public:
    	explicit GlTestWidget(QWidget *parent = 0) : QGLWidget(parent) {}
    
    protected:
    	void resizeGL(int h, int w) override {
    		glViewport(0, 0, (GLint)w, (GLint)h);
    	}
    
    	void paintGL() override {
    		glClearColor(1.0f, 0.7f, 0.0f, 1.0f);
    		glClear(GL_COLOR_BUFFER_BIT);
    	}
    };
    
    struct MainWindow : public QMainWindow
    {
    	MainWindow() {
    		setCentralWidget(new GlTestWidget(this));
    	}
    };
    
    int main(int argc, char *argv[])
    {
    	QApplication a(argc, argv);
    	MainWindow w;
    	w.show();
    
    	return a.exec();
    }
    

  • Qt Champions 2016

    Hi
    The docs
    http://doc.qt.io/qt-5/qglwidget.html
    says
    "This class is obsolete. It is provided to keep old source code working. We strongly advise against using it in new code."

    So no, it should still work.

    Have you tried other sample
    http://doc.qt.io/qt-4.8/qt-opengl-hellogl-example.html
    (C:\Qt\Examples\Qt-5.7\opengl\legacy\hellogl)

    One possible cause could be you do not use a
    void GLWidget::initializeGL()

    But it would good to know if that sample also produce black on Qt 5.7

    Update:
    Win 10 Desktop Pc , Qt 5.7 , Sample works here. using QGLWidget.
    Main difference to your sample is
    void GLWidget::initializeGL()
    {
    initializeOpenGLFunctions(); <<<<< important?

    and
    class GLWidget : public QGLWidget, public QOpenGLFunctions_1_1


  • Qt Champions 2016

    Works for me without a glitch on Qt 5.7.1, Linux 4.6.0 kernel.



  • @mrjj said in QGLWidget ceased to work in Qt 5.7?:

    Main difference to your sample is
    void GLWidget::initializeGL()
    {
    initializeOpenGLFunctions(); <<<<< important?

    and
    class GLWidget : public QGLWidget, public QOpenGLFunctions_1_1

    No, my application won't work like that, it uses many OpenGL functions that are not provided by QOpenGLFunctions.

    Forgot to add that I'm having problems on Windows 10. The same app works fine on Mac.


  • Qt Champions 2016

    Well, you should test on other win 10 then.
    The QGLWidget samples seems to work fine on win 10 when i run it.

    Did you try the sample ? Does it also produce black on that pc?



  • @mrjj
    My glClear example from the first post produces black when combined with Qt 5.7 and orange (expected) with 5.5.
    Meanwhile, hellogl example crashes.


  • Qt Champions 2016

    @Violet-Giraffe
    So it seems that QGLWidget and that win 10 have issues?
    Tried hellogl on 3 very different win 10 pc and it worked.

    So if same sample crashes on the test pc you have, i would
    think its driver issue that first surfaces when using 5.7.



  • OK, I have tried replacing the direct GL function calls with QOpenGLFunctions_1_1 (and then QOpenGLFunctions_2_0). But some of the functions I need are not loaded by that class. E. g. glMaterialfv: there is a method for that

    inline void QOpenGLFunctions_2_0::glMaterialfv(GLenum face, GLenum pname, const GLfloat *params)
    {
        d_1_0_Deprecated->f.Materialfv(face, pname, params);
    }
    

    Here f is a structure holding pointers to OpenGL functions, and it doesn't have a single non-nullptr field.



  • The example's problem is the same: it didn't load any OpenGL functions into d_1_0_Deprecated->f. But I don't care about the example. You know my drivers are OK and they do supply these functions because the same code works when compiled and linked with Qt 5.5 (didn't try 5.6) and calling OpenGL functions directly from OpenGl32.lib.


  • Qt Champions 2016

    ok, But you dont find it odd that the
    hellogl sample here works with 5.7 on all win 10 , i could test on?

    But on that pc, you say it crash?



  • Yes, it crashes because it fails to load OpenGL function pointers into d_1_0_Deprecated->f. I'm fairly sure it's a Qt bug. And there's no saying how many users of my app will experience this bug as well.


  • Qt Champions 2016

    @Violet-Giraffe
    well if its a bug in Qt it must
    be with certain hardware or drivers as i cannot make sample fail with the
    hardware with win 10, i have at work.

    You can look in
    https://bugreports.qt.io/secure/Dashboard.jspa
    if it has been reported before.



  • @mrjj Indeed, it seems to occur only on some systems, but a bug nevertheless. I didn't find a corresponding issue in the tracker. I would report it but don't see a point - they probably won't be able to reproduce it as well. Seeing that the bugs I reported 2 years ago still aren't fixed, I'm not enthusiastic about spending more time trying to make Qt better. Just need to find the quickest way to restore functionality of my application.


  • Qt Champions 2016

    Well I had hoped I could reproduce it
    as clear reproduction steps is needed.

    However, since QGLWidget is considered obsolete in 5.7,
    I doubt the devs will spend much energy to correct it anyway.



  • The problem with hellogl example is not in QGLWidget. I'm about to try QOpenGLWidget instead, and I'm sure it will fail just the same. It's the QOpenGLFunctions_xx classes that are broken, although it doesn't explain why my application stopped working. I never used these classes.



  • No functions are loaded into QOpenGLFunctions_x_x::d_x_x_Deprecated tables. That's d_1_0_Deprecated, d_1_2_Deprecated and d_1_4_Deprecated. And I need some functions from there. So it makes no difference what kind of widget I will use, the old or the new one.

    Unless I make direct OpenGL calls, of course, but direct calls are broken with Qt 5.7 as well. I don't understand why, but they are.



  • Update: the required functions are loaded in Qt 5.5 - but not in 5.7. I have Qt sources, I can debug if someone tells me where to look.


  • Qt Champions 2016

    @Violet-Giraffe

    direct calls are broken with Qt 5.7 as well. I don't understand why, but they are.

    Then the problem (probably) has little to do with Qt. Qt only resolves the functions' addresses for you. List the symbols from your OpenGL library (the one you link against), see if it exports the deprecated functions you want to use.

    Update: the required functions are loaded in Qt 5.5 - but not in 5.7. I have Qt sources, I can debug if someone tells me where to look.

    <Qt source dir>/qtbase/src/gui/opengl
    


  • @kshegunov said in QGLWidget ceased to work on Windows in Qt 5.7?:

    List the symbols from your OpenGL library (the one you link against), see if it exports the deprecated functions you want to use.

    I link with Windows default OpenGL32.lib. It's the same in both cases.

    <Qt source dir>/qtbase/src/gui/opengl
    

    That's not helpful.


  • Qt Champions 2016

    @Violet-Giraffe said in QGLWidget ceased to work on Windows in Qt 5.7?:

    I link with Windows default OpenGL32.lib. It's the same in both cases.

    There's no such thing. The lib file is part of the Windows SDK.
    Are you using a statically built Qt? How did you install, Qt may be linked against another GL, or it may be resolving the functions at runtime (which is rather probable on desktop). Just list the symbols from opengl32.dll and see what's exported.

    That's not helpful.

    How so? It is where you should look if you intend to debug ...



  • @kshegunov said in QGLWidget ceased to work on Windows in Qt 5.7?:

    The lib file is part of the Windows SDK.

    My point exactly! It's the same no matter which Qt version I build with. I have a normal dynamic Qt obtained with the online installer, no tricks.
    Moreover, I only have one instance of opengl32.dll on my computer so there's no point in checking its exports - we already know it works and the problem is somewhere in Qt, most likely.

    How so? It is where you should look if you intend to debug ...

    Yeah, but I need to know where to set breakpoints to debug OpenGL 1.0 linking issue, not which folder the sources are in.



  • Hi! Can you tell us which OpenGL core profile you're using?



  • @Wieland
    I've tried 1.1 and 2.0. I need 2.0 eventually. I even specified it with setFormat - to no avail still.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.