How to display a splash screen in Qt ?

Is this the correct way to display a splash screen in Qt ?
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.

Make sure you have the splashpage.png file in the directory. Use the GIMP http://www.gimp.org to create a simple splashpage image of 600 x 400. When you reply to this question please do not half or snippet your code please reply with the full source code and make sure you test you code before you post it. Snippets and half code is very frustrating to a newbie coder.

Instructions to run this code:

Create a directory, such as SplashPageApplication

Change into the directory

Create a file named main.cpp in your newly created directory, type/copy/paste the code below in the file save as main.cpp

Well, you create the Splash Screen and you show() it. But you are NOT running an event loop until the app.exec() at the very end. Your qApp->processEvents() probably is sufficient that the Splash Screen gets drawn once, but it certainly won't be "responsive" to user actions. processEvents() processes all pending events, yes. But it won't block and run a "loop" to wait for upcoming messages. Instead it will simply return as soon as possible!

I would use something like this and do all the required "initialization" work in a separate thread:

@MuldeR
For the above code are these two or three separate files such as main.cpp, mainwindow.cpp, mainwindow.h ? Can you please tell me what you are naming your files. I rather have the full source code that you are submitting then snippets of code. I am having problems compiling your code using qmake -project, qmake, make.
Did you test this code ?
Does it work ?

C++ does not force you to put each class in a separate .cpp files (with a corresponding .h file), but it usually is a good idea. If you want to, you can put everything into a single file of course. You can name your files as you like.

Okay this is your code, that I will post below please fix your code so it compiles without errors. Is it possible for you to do that ?
All I did was add the #include directives and move the second half of the code to the beginning.
I would really like to see the full source code of your example/suggestion which works.
All you have to do is copy/paste the corrected code in the box it's not too hard to do is it ?
@
#include <QtCore>
#include <QApplication>
#include <QPixmap>
#include <QSplashScreen>
#include <QWidget>
#include <QMainWindow>
#include <QTimer>
#include <QThread>

If you have a specific question, feel free to ask. But you can't expect that somebody else will write the complete code for you. Instead you better learn how to do it yourself. But as it seems you have more problems with C++ in general than with Qt in particular, I would suggest to start with a basic C++ book/tutorial though...

Hey KA510, I looked at the code you posted and although it is interesting it is not exactly what I am looking for. I noticed that this code you posted works only on Ubuntu Linux and I was looking for code that worked on both Linux and Windows. So far the closest I have come to what I am looking for is the following code below.

Create a main directory and inside of the directory created an images directory, store your created splash.png image inside of the images directory. Then copy all 5 files into the main directory and use Qt Creator to create a mainwindow.ui file with the dimensions of 600x400. Then run qmake -project, qmake, make. This application runs on Ubuntu Linux and Windows. However, I am trying to figure out how to maximize the main application window to fit the whole computer screen. At this time all it does is show the splashscreen for a few seconds then it kicks it out to a small window/box of the main application.

It's probably because they want to point out a specific aspect and therefore paste the relevant lines.

Posting loads of code on a forum isn't exactly what encourages people to post a reply. If you post your complete program and ask "why it isn't working?" it will be pretty much impossible to give an useful answer. If, instead, you only post a small excerpt from your program - the specific part where you have a problem/question - then it will be much easier for other users to understand the issue and to give the desired reply...

Qt calls its header files exactly like the class they define; shouldn't be too hard to figure out the right include ;)

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.

qmake -project
qmake
make

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.

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.