关于 initializeOpenGLFunctions 返回 false 的问题

question on initializeOpenGLFunctions returning false

我 运行 在 initializeGL() 失败后出现以下段错误。关于什么可能导致这种情况的任何想法?当我从 QOpenGLFunctions 继承时没有问题,但我需要 v3.0 功能。

class MyGLWidget : public QOpenGLWidget, protected QOpenGLFunctions
QOpenGLFunctions_3_3_Compatibility::glClearColor (this=0x5d3c40, red=0, green=0, blue=0, alpha=1) at /usr/include/qt5/QtGui/qopenglfunctions_3_3_compatibility.h:1064
1064        d_1_0_Core->f.ClearColor(red, green, blue, alpha);
class MyGLWidget : public QOpenGLWidget, protected QOpenGLFunctions_3_3_Compatibility
{
    Q_OBJECT
...
};

    void initializeGL() override {
        makeCurrent();
        bool ret =  initializeOpenGLFunctions();
        std::cout << std::boolalpha << ret << std::endl; // FALSE
        glClearColor(0, 0, 0, 1); // CRASH
    }

我解决了这个问题如下。我从 QOpenGLFunctions 继承,然后在需要时在我的案例中使用相应的核心配置文件 3.3

class MyGLWidget : public QOpenGLWidget, protected QOpenGLFunctions
{
   Q_OBJECT
...
protected:
   void initializeGL() override {
        initializeOpenGLFunctions();
        auto * glFunctions = QOpenGLContext::currentContext()->versionFunctions<QOpenGLFunctions_3_3_Core>();
        glFunctions->glClearColor(0, 0, 0, 1);
    }
};