How to display a splash screen in Qt
Article Metadata
Tested with
Devices(s): Emulator
Compatibility
Platform(s): S60 3rd Edition FP1, S60 3rd Edition FP2, S60 5th Edition
Article
Keywords: QSplashScreen
Created: james1980
(12 Jan 2009)
Last edited: hamishwillee
(11 Oct 2012)
Contents |
Overview
This code snippet demonstrates how to display a splash screen before your application loaded using QSplashScreen.
A splash screen is a widget that is usually displayed when an application is being started. Splash screens are often used for applications that have long start up times (e.g. database or networking applications that take time to establish connections) to provide the user with feedback that the application is loading. The splash screen may usually appear in the center of the screen.
Preconditions
- Download and install the Qt SDK
Various Function
- Makes the splash screen wait until the widget mainWin is displayed
splash.finish(&window);
- Draws the message text onto the splash screen with color and aligns the text according to the flags in alignment
splash.showMessage("Wait...");
Source File
#include <QApplication>
#include <QPixmap>
#include <QSplashScreen>
#include <QWidget>
#include <QMainWindow>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QPixmap pixmap("c://designer.png");
QSplashScreen splash(pixmap);
splash.show();
splash.showMessage("Wait...");
qApp->processEvents();//This is used to accept a click on the screen so that user can cancel the screen
QMainWindow window;
window.setStyleSheet("* { background-color:rgb(199,147,88); padding: 7px}");
window.show();
splash.finish(&window);
return app.exec();
}
Screenshot
.


Splash screen is used during application startup.It's just a start up image with some messages showing to the users.It represents network connections,loading some items,etc.. as a message displayed on the Splash screen.How can it be done in the application is shown in this article and it uses simple code for Qt.
--vkmunjpara 18:59, 17 September 2009 (UTC)
Jahan.geo - Mistake in the line qApp->processEvents()
It should be qApp.processEvents()!!!!!
mind the dot after object qApp, not as pointer.jahan.geo 12:49, 21 October 2011 (EEST)
Entricular - The above code is wrong and needs to be corrected see the following code below
Use a program such as the GIMP http://www.gimp.org to create your splashpage.png image and include the splashpage.png in your images application directory.
Run the following commands:
Execute the program:
I am tired of people posting flawed, incomplete and unconfirmed Qt code, test your code before you post it to make sure it works so others can follow and learn. Posting snippets of code doesn't help it is very frustrating, in the future post the full source code. This code was tested and confirmed( it works ) on Ubuntu Linux 10.04 LTS with Qt 4.7.4 SDK installed. I tested the code with Windows Vista and Qt 4.7.4 and it did not work.
entricular 16:21, 28 April 2012 (EEST)