QOpenGLWidget show black screen

前端 未结 3 1905
北荒
北荒 2021-01-28 20:38

I tried the QOpenGLWidget example described here: https://stackoverflow.com/a/31524956/4564882

but I get only a black widget. The code is exactly the same. this the code

3条回答
  •  半阙折子戏
    2021-01-28 21:13

    I had a black screen on desktop. I solved the problem by adding this line of code:

    QCoreApplication::setAttribute(Qt::AA_UseDesktopOpenGL);
    

    For example, put it here:

    #include "widget.h"
    
    #include 
    
    int main(int argc, char *argv[])
    {
        QCoreApplication::setAttribute(Qt::AA_UseDesktopOpenGL);
        QApplication a(argc, argv);
        Widget w;
        w.show();
        return a.exec();
    }
    

提交回复
热议问题