从网上下了qpicturebox控件,从qopenglwidget派生,然后发现运行时会偶发闪退,而在我另外一台电脑则用不起来,上网搜索了一下,大概有如下的解决思路:
1. 需要setFormat
int main(int argc, char **argv) { QApplication app(argc, argv); QSurfaceFormat format; format.setDepthBufferSize(24); format.setStencilBufferSize(8); format.setVersion(3, 2); format.setProfile(QSurfaceFormat::CoreProfile); QSurfaceFormat::setDefaultFormat(format); MyWidget widget; widget.show(); return app.exec(); } 上面的版本号得根据实际的来 QOpenGLWidget Class | Qt OpenGLhttps://doc.qt.io/qt-6/qopenglwidget.html#details
那实际的版本号怎么获取呢,这个链接说:检查OpenGL的版本_查看opengl版本_金色熊族的博客-CSDN博客
2. 我下载的那个类,派生于QOpenGLFunctions_3_3_Core,为什么要指定版本呢?我打算换成
通用的QOpenGLFunctions
目前还没测试 一会机器空了就测试行不行的通