当我尝试创建一个QOpenGLContext时,我得到了一个分段错误。我的代码如下:
if (!m_context) {
m_context = new QOpenGLContext(this);
m_context->setFormat(requestedFormat());
m_context->create();
}m_context被声明为
QOpenGLContext *m_context;在私有下
该类继承自QWindow和QOpenGLFunctions
class DisplayWindow : public QWindow, protected QOpenGLFunctions在类的构造函数中,m_context被设置为0。
为什么会发生这种分段错误?
发布于 2013-12-06 17:23:26
问题很可能出现在您没有显示的代码中。
This解释了如何做你想做的事情。您需要使用setSurfaceType(OpenGLSurface);设置曲面类型:
MyGLWindow(QScreen *screen)
: QWindow(screen), QOpenGLWidget(parent)
{
setSurfaceType(OpenGLSurface);
create();
// Create an OpenGL context
m_context = new QOpenGLContext;
m_context->create();
// Setup scene and render it
initializeGL();
paintGL()
}https://stackoverflow.com/questions/20420093
复制相似问题