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();
}
↧