Quantcast
Channel: Qt DevNet forums: Qt Quick 1283365070**
Viewing all articles
Browse latest Browse all 4972

DIsplay another QML file during initialization

$
0
0
Hi, I’m working on an application which has a quite long initialization procedure (connect to a server, get data from the server, load QML files, images,…). I would like to display another QML file (a splashscreen) during the initialization of the application. I tried this: Create an QGuiApplication and a QQuickView objects call SetSource() on QQuickView to load the splashscreen QML file and then show() start a QThread that will run the init procedure call the method exec() of the QGuiApplication object. when the thread is finished, call SetSource() on the QQuickView again to make it load the final QML file. By doing this, I expect that the application is running, and that the splashscreen is displayed during the execution of the thread but… It’s not the case. For testing, the initialization thread only call msleep() so, it does nothing During the execution of the thread, a blank window is opened, it doesn’t display the splashscreen (ConnectingDialog.qml). It’s only when the thread exits that the windows is updated with the content of the main QML file. ConnectingDialog.qml is a simple module that displays a black rectangle with some text Here is my code: Some declarations: QGuiApplication* app; QThread* startThread; QQuickView* viewer; The Start() function of the application int MyApp::Start() {     QDir directory(QCoreApplication::applicationDirPath());     QString path = directory.absoluteFilePath("qml/ConnectingDialog.qml");       viewer->setSource(QUrl::fromLocalFile(path));     viewer->show();       this->connect(this->startThread, SIGNAL(started()), SLOT(RunStartSequence()));     this->connect(this, SIGNAL(finished()), SLOT(OnStartSequenceFinished()));     this->startThread->start();     return 0; } The function called by the startThread: void MyApp::RunStartSequence() {     this->startThread->msleep(5000);     emit finished(); } And the slot OnStartSequenceFinished(): void MyApp::OnStartSequenceFinished() {     QDir directory(QCoreApplication::applicationDirPath());     QString path = directory.absoluteFilePath("qml/main.qml");       viewer->setSource(QUrl::fromLocalFile(path)); } main()     QGuiApplication app(argc, argv);     MyApp myApp;       myApp.Start();     return app.exec(); I don’t understand why my splashscreen is not displayed during the execution of the init thread. Can you help me? Thanks in advance!

Viewing all articles
Browse latest Browse all 4972

Trending Articles