How to display a splash screen in Qt ?
You need to add a Qt resource file. In order for your code to display on Windows Vista, 7.
This is your code and I included what the Qt Resource file should look like and then you can run. Hopefully, your system is configured to run Qt commands from the command line.
Create a directory and pack all your source code and files into this directory
The files would consist of main.cpp, splash.png, data.qrc file. Then run the following. Without this data.qrc resource file your splash screen image did not display on my Windows Vista/7 system. However, it did run on Ubuntu Linux without the data.qrc file.
This is your code I included the #include directives and added the Qt Resource file known as data.qrc
What your code does is display a full page splash screen for 3 seconds. You may want to minimize the full screen splashscreen and have it display for 5 seconds. In my opinion your code needs to be tweaked.
- #include <QtCore>
- #include <QApplication>
- #include <QPixmap>
- #include <QSplashScreen>
- #include <QWidget>
- #include <QMainWindow>
- #include <QTimer>
- #include <QThread>
- #include <QDesktopWidget>
- #include <QPainter>
- int main(int argc, char* argv)
- QApplication app(argc, argv);
- QImage splashScrImage ("splash.png");
- QPainter painter (&splashScr);
- painter.fillRect(splashScr.rect(), Qt::black);
- QRect scaledRect = scaled.rect();
- painter.drawImage(scaledRect, scaled);
- QPixmap Logo;
- QTimer::singleShot(3000, &splashScrWindow ,SLOT(close()));
- return app.exec();
It was just a code snippet and not supposed to run out of the box. You may be suprised to find out that you’re the only one who has the expectation to receive fully compilable code in forum threads.
BTW if the file “splash.png” is located in the same folder as the executable, the code will work without a resource file on any platform.
Anyways thanks for the effort.
Hello, KA51O and MuldeR
This is a link to the splash page code I was modifying, here you will find a sample application created using the display splash page method. See if you can compile this and run it on your computer and tell me what you think about it.