Unsolved QQuickView Scene Graph's OpenGLContext is NULL
-
QSurfaceFormat format = QSurfaceFormat::defaultFormat(); format.setVersion(4, 3); format.setProfile(QSurfaceFormat::CompatibilityProfile); QSurfaceFormat::setDefaultFormat(format); QQuickView *qview = new QQuickView(); qview.setFormat(format); qview.show();
After the .show(), the scene graph is initialized ( confirmed by checking QQuickWindow::isSceneGraphInitialized() ), but the QOpenGLContext::currentContext() is still NULL.
I also try to connect a SLOT function with SIGNAL QQuickWindow::beforeRendering (as stated in http://doc.qt.io/qt-5/qquickwindow.html), with Qt::DirectConnect. But the SLOT function is not trigged after qview.show().How to enable the openglcontext in the QQuickView?
Thanks! -
Maybe it solve the pointer if calling QOpenGLContext::makeCurrent()
-
If calling QOpenGLContext::makeCurrent(), I get the Error: a nonstatic member reference must be relative to a specific object.
if I called resetOpenGLState(), I get Error Info:
QOpenGLFramebufferObject::bindDefault() called without current contextI used a renderer from QQuickFramebufferObject::createRenderer() in QQuickView. According to the Qt Document, they share the opengl context. But in QQuickView, the opengl context is NULL.
-
I temporarily solve the problem by using the shared context.
Before initiate QApplication (QApplication app(argc, argv);), set the attribute to use globalshareContext:
QApplication::setAttribute(Qt::AA_ShareOpenGLContexts);
I get the QOpenGLContext::currentContext() in function QQuickFramebufferObject::createRenderer(), set it to be a globalshareContext, then create an OpenGL Context "QOpenGLContext *m_context = new QOpenGLContext" in QQuickView. After initialize the renderer from QQuickFramebufferObject, set it to share this globalshareContext.But I think a good solution is still find out the default OpenGL Context in QQuickView' Scene Graph. Qt shares this context with the renderer from QQuickFramebufferObject (according to Qt Document). Hope I can find this solution later.
Thanks.