Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
How to use QGLWidget as the viewport of a QGraphicsView and use its QGLContext afterward?
rdebroiz last edited by
I'm trying to use a QGLWidget as the viewport of a QGraphicsView and use its QGLContext afterward.
I found a satisfactory way to do it under Linux or OSX but not with Window. My Qt version is Qt-4.8.5.
Using the following snippet :
QGraphicsView *graphicsView = new QGraphicsView;
QGLContext *glContext = new QGLContext(QGLFormat::defaultFormat());
QGLWidget *glWidget = new QGLWidget(glContext);
qDebug() << "1" << glContext;
qDebug() << "2" << glWidget->context();
qDebug() << "3" << QGLContext::currentContext();
qDebug() << "4" << glWidget->context();
qDebug() << "5" << QGLContext::currentContext();
qDebug() << "6" << glContext->isValid();
qDebug() << "7" << glWidget->context()->isValid();
I get as output :
With Windows, it appears that the context I created is invalid right after calling setViewport on my QGraphicsView, then If I try to call create() or makeCurrent() on it, it end up on a crash.
I can't figure out what is happening. Is it a normal bahavior ?
Can someone higlight me what's hapening here, and what the corrrect way to proceed ?