在main函数中加入AA_UseSoftwareOpenGL或者AA_UseOpenGLES。我选择的是加入第二个,因为加入第一个会出现崩溃等现象,貌似需要openGL2.1或者更高。而我的电脑是openGL ES 2. 0所以不支持使用第一个。
查看电脑OpenGL版本的方式可以参考
https://blog.csdn.net/a137748099/article/details/123018715
具体代码为:
#include <QOffscreenSurface>
#include <QOpenGLContext>
#include <QOpenGLFunctions>
#include <QDebug>
QOffscreenSurface surf;
surf.create();
QOpenGLContext ctx;
ctx.create();
ctx.makeCurrent(&surf);
GLint major, minor;
ctx.functions()->glGetIntegerv(GL_MAJOR_VERSION, &major); //gl大版本(整型)
ctx.functions()->glGetIntegerv(GL_MINOR_VERSION, &minor); //gl小版本(整型)
qDebug() << "OpenGL Version Info:" << (const char *)ctx.functions()->glGetString(GL_VERSION);
qDebug() << "OpenGL Version Major:" << major << "OpenGL Version Minor:" << minor;
ctx.doneCurrent();