Stop QQuickView showing before QML is rendered?
-
Hi, I have the following scenario
main.qml:
//very slow QML code :)
main.cpp
QQuickView v(QStringLiteral("qrc:/main.qml")); v.show();
The QQuickView shows a blank white screen briefly before the QML is loaded.
Is there anyway to prevent the view from showing until the QML is rendering?The QML scene graph does not get initialized until after QQuickView is shown, I would like a way to have everything ready to go before hand.
Current hacky solution is to set the view opacity to 0 until QQuickWindow::afterRendering is fired.
Unfortunately tidying up the slow QML code isn't an option right now...
Thanks in advance!
-
Since you didn't provide more information, I can only give you some advice based on experience.
I'm not sure about your qt version. If you a using qt 5.1(and higher), you should tryQQmlApplicationEngine
. Here is an exampleQQmlApplicationEngine engine; const QUrl url(u"qrc:/MainForm.qml"_qs); QObject::connect(&engine, &QQmlApplicationEngine::objectCreated, &app, [url](QObject *obj, const QUrl &objUrl) { if (!obj && url == objUrl) QCoreApplication::exit(-1); }, Qt::QueuedConnection); engine.load(url);
-
Since you didn't provide more information, I can only give you some advice based on experience.
I'm not sure about your qt version. If you a using qt 5.1(and higher), you should tryQQmlApplicationEngine
. Here is an exampleQQmlApplicationEngine engine; const QUrl url(u"qrc:/MainForm.qml"_qs); QObject::connect(&engine, &QQmlApplicationEngine::objectCreated, &app, [url](QObject *obj, const QUrl &objUrl) { if (!obj && url == objUrl) QCoreApplication::exit(-1); }, Qt::QueuedConnection); engine.load(url);
@Kamichanw Sorry, using 5.15.2 but moving to 6.5.x in the next couple of months
To give more info we are using multiple QQuickViews and QQuickWidgets, that share the one QQmlEngine instance.
I'm not sure if using multiple QQmlApplicationEngines is an alternative