How to create a splash screen with an induced delay

From Qt Wiki
Jump to: navigation, search

En Ar Bg De El Es Fa Fi Fr Hi Hu It Ja Kn Ko Ms Nl Pl Pt Ru Sq Th Tr Uk Zh

We have QSplashScreen which is used to cover up the starting delay of the program. Some times the programs might be quick enough, so that the splash screen may not be visible. We may induce some delay to show the splash, as a decoration!

Single shot timer QTimer will do.

#include <QApplication>
#include <QSplashScreen>
#include <QTimer>
#include "mainwindow.h"

int main(int argc, char *argv[])
    QApplication app(argc, argv);
    QPixmap pixmap("splash.jpg");
    QSplashScreen splash(pixmap, Qt::WindowStaysOnTopHint);;
    QTimer::singleShot(5000, &splash, &QWidget::close); // keep displayed for 5 seconds
    MainWindow mainWin;
    return app.exec();