vs 顯示QOpenGLWidget崩潰

原文鏈接:https://blog.csdn.net/GengWenhui123/article/details/86640525

轉載自:https://blog.csdn.net/GengWenhui123/article/details/86640525

由於顯卡的差異,有時候在創建QOpenGLWidget時需要初始化顯卡

第一次創建QOpenGLWidget失敗

#include "QtGuiApplication2.h"
#include <QtWidgets/QApplication>
#include <QOpenGLWidget>
int main(int argc, char *argv[])
{
//     QSurfaceFormat format;
//     format.setDepthBufferSize(24);
//     format.setStencilBufferSize(8);
//     format.setVersion(4, 3);
//     format.setProfile(QSurfaceFormat::CoreProfile);
//     QSurfaceFormat::setDefaultFormat(format);
    QApplication a(argc, argv);
    QOpenGLWidget w;
    w.show();
    return a.exec();
}

運行後崩潰:

 

如果出現上述問題,可以嘗試把註釋打開在運行

 

源碼如下:

#include "QtGuiApplication2.h"
#include <QtWidgets/QApplication>
#include <QOpenGLWidget>
int main(int argc, char *argv[])
{
     QSurfaceFormat format;
     format.setDepthBufferSize(24);
     format.setStencilBufferSize(8);
     format.setVersion(4, 3);
     format.setProfile(QSurfaceFormat::CoreProfile);
     QSurfaceFormat::setDefaultFormat(format);
    QApplication a(argc, argv);
    QOpenGLWidget w;
    w.show();
    return a.exec();
}

如果還出現問題,可以改變版本號試試

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章