Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

SplashScreen implementation question



  • Hello,

    I have an embedded Qt application for Linux which has the following startup code:

    int main(int argc, char *argv[])
    {

       QApplication app(argc, argv);
    // Startup actions neeeded to display AppView correctly
    // Black screen is shown for several seconds
    // ...
    
    QQuickView AppView;
    AppView.setSource(QUrl(QStringLiteral("main.qml")));
    AppView.resize(480, 800);
    AppView.show();
    return app.exec();
    

    }

    I'd like to remove the black screen shown before AppView and to display QML animation
    instead of it.

    I see two possible options here but non of them is clear. Could you please advice
    which one of them is more correct and also comment/answer the questions in each.

    1. To display QSplashScreen at the beginnning of main().

    int main(int argc, char *argv[])
    {

    QApplication app(argc, argv);
    QSplashScreen *splash = new QSplashScreen();
    splash->show();
    
    // Startup actions neeeded to display AppView correctly
    // Black screen is shown for several seconds
    // ...  
    

    }

    The question here is what API to use to attach QML animation to QSplashScreen?
    QSplashScreen inherits from QWidget, and so as I understand, no API like QQuickWidget::setSource() can be used.

    1. To display another QQuickView at the beginnning of main() with attached QML animation.

    int main(int argc, char *argv[])
    {

    QApplication app(argc, argv);
    QQuickView SplashView;
    SplashView.setSource(QUrl(QStringLiteral("SplashScreen.qml")));
    SplashView.resize(480, 800);
    SplashView.show();
    app.exec();
    
    // Startup actions neeeded to display AppView correctly
    // Black screen is shown for several seconds
    // ...
    
    QQuickView AppView;
    AppView.setSource(QUrl(QStringLiteral("main.qml")));
    AppView.resize(480, 800);
    AppView.show();
    

    }

    The question here is how to to close the SplashView and to display AppView on top of it?

    Thanks


  • Moderators

    @ml16685
    IMO save yourself some struggle and simply use a Loader QML element as your root item in the window.
    Do not spawn multiple event loops, QML engines, etc.



  • @raven-worx Thank you, will try this approach.


Log in to reply