[SOLVED] Creating a QQuickView with a shared opengl context.
-
It's not really an elegant solution but i think i found one.
Before setting QML file, (setSource) connect a slot to QQuickWindow::sceneGraphInitialized() signal like this :
@connect(this, SIGNAL(sceneGraphInitialized()), this, SLOT(onSceneGraphInitialized()), Qt::DirectConnection);@when it hits the slot, do following :
@
openglContext()->blockSignals(true);
openglContext()->doneCurrent();
openglContext()->setShareContext(openGLContextToBeSharedWith);
openglContext()->setFormat(requestedFormat());
openglContext()->create();
openglContext()->makeCurrent(this);
openglContext()->blockSignals(false); // <- Forgot this line before
@ -
hi Turgut,
How did you display it after extending the class?
-
As it was.
@
class MyView : QQuickView
{
Q_OBJECT
public :
MyView(QWindow *parent = 0) : QQuickView(parent)
{
connect(this, SIGNAL(sceneGraphInitialized()), this, SLOT(onSceneGraphInitialized()), Qt::DirectConnection);setPersistentOpenGLContext(true); backgroundContext = new QOpenGLContext(this); backgroundContext->setFormat(requestedFormat()); backgroundContext->create(); backgroundContext->makeCurrent(this); static bool openGLExtensionsInitialized = false; if (!openGLExtensionsInitialized) { OpenGL::initialize(backgroundContext); openGLExtensionsInitialized = true; } backgroundContext->doneCurrent(); }
protected slots :
onSceneGraphInitialized() {
openglContext()->blockSignals(true);
openglContext()->doneCurrent();
openglContext()->setShareContext(backgroundContext);
openglContext()->setFormat(requestedFormat());
openglContext()->create();
openglContext()->makeCurrent(this);
openglContext()->blockSignals(false);
}
protected :
QOpenGLContext *backgroundContext;
};void someInitFunction()
{
MyView *view = new MyView();
view->setSource(QUrl("qrc:/script/init.qml"));
view->show();
app.exec();
}
@ -
Many Thanks Turgut :)
I noticed what I was missing