1

There is an example in the documentation providing the following code, which seems to be quite simple :

int main(int argc, char *argv[])
{
    QApplication app(argc, argv);
    QPixmap pixmap(":/splash.png");
    QSplashScreen splash(pixmap);
    splash.show();
    app.processEvents();
    ...
    QMainWindow window;
    window.show();
    splash.finish(&window);
    return app.exec();
}

Now the thing is that I am using QApplication, create an engine and open my QML files like this:

engine->load(QUrl(QLatin1String("qrc:/qml/main.qml")));

And from the documentation I cannot really understand how to go the QMainWindow way like in the example, without passing a URL of the file as an argument (there is no such function available). Do I have to write a C++ class derived from QMainWindow or something like this? Or am I missing another important point? I am furthermore happy about any other suggestions of getting QSplashScreen to work.

L. Srd
  • 91
  • 1
  • 4
  • I think the QSplashScreen you are talking about is from the QWidget-Library and not from the QtQuick/QML. See here: http://doc.qt.io/qt-5/qtquick-window-example.html for a solution in QML. – derM - not here for BOT dreams Nov 18 '16 at 10:37
  • Thank you so much for this helpful hint! It works and looks very professional now. The only thing that bugs me a bit is that this QML style splash screen is only loaded once the QML application is already built completely, while I think the widget approach nicley bypasses the time from clicking "run" and having all QML files loaded. Did I unterstand this right? Does somebody know IF there is a QML way to simulate this behaviour? – L. Srd Nov 18 '16 at 13:57
  • 1
    You can do that with a QtQuick based splashscreen as well as long as your main UI is loaded into a different engine. E.g. you could use a `QQuickView` for the splashscreen content. If you have a `QApplication` instance and thus access to the widget based `QSplashScreen` you can still use that you just need to trigger its closing from the main content's QML or for example by connecting the `QQmlApplicationEngine`'s `objectCreated()` signal to the splashscreen's `close()' slot – Kevin Krammer Nov 19 '16 at 10:56

0 Answers0