Warning: INSERT command denied to user 'dbo292345962'@'' for table 'watchdog' query: INSERT INTO watchdog (uid, type, message, variables, severity, link, location, referer, hostname, timestamp) VALUES (0, 'php', '%message in %file on line %line.', 'a:4:{s:6:\"%error\";s:12:\"user warning\";s:8:\"%message\";s:399:\"INSERT command denied to user 'dbo292345962'@'' for table 'captcha_sessions'\nquery: INSERT into captcha_sessions (uid, sid, ip_address, timestamp, form_id, solution, status, attempts) VALUES (0, '08a325e0bd184f68906759a838e56f9e', '', 1591083645, 'comment_form', 'c287d913d1826a149d4e1f42872d22b6', 0, 0)\";s:5:\"%file\";s:62:\"/homepages/25/d199835659/htdocs/ID/modules/captcha/captcha.inc\";s:5:\"%line\";i:99;}&# in /homepages/25/d199835659/htdocs/ID/includes/database.mysql.inc on line 135
Qt Splash Screen | Inferno Development

Qt Splash Screen

Qt Splash Screen

Having a beautiful splash screen can give your program some class. Impress some of your clients as well if you use Qt to program. I'll show you how to edit the Splash Screen message, program the Splash screen, and play with the images.

If you look at the screenshot provided, you can see what we can create using splash screen. Splashscreens are only beneficial to large programs and programs that need to load a lot of modules or files. It usually won't look good for small programs that load pretty quick.

Using the class QSplashScreen we can create our splash screen and play around with it.

Our qt main cpp file:

#include <QtGui>
#include <windows.h>

int main(int argc, char *argv[]) {
        QApplication App(argc, argv);
        QPixmap pix(":/twirl.png");
        QSplashScreen splash(pix);
        splash.showMessage("Loading Processes");
        splash.showMessage("Loading Modules");
        // do some work with your classes
        QMainWindow window;
        QLabel ql(&window);
        return App.exec();

We have created a project file and a resource file, to include a twirl.png (do not try and include JPG, as Pixmaps don't allow it).

The above code is easy to understand, we create our application. Then we create a QPixmap or an image, grab the image from our resource using the colon. Then we create a QSplashScreen, assign the pixmap to it. Then we show the SplashScreen, process our application events, then we can also show messages using ShowMessage. We also create a label that has our image as well so that we know when the program is loaded.

I have commented out the Sleep (used in windows.h and win32 programs) and the finish so that we can actually see our splashscreen before it disappears. In a normal program you'd need to finish() the splashscreen so that once your main window class is loaded and all your program files are ready, you can end the splash screen.

Of course then we run the whole thing using app.exec().

Here's how our project file and resource file looks in case you have had any trouble with that. QtTest.pro :

RESOURCES = res.qrc

# Input
SOURCES += qtmain.cpp

res.qrc, our Qt Resource File.

<qresource prefix="/">

You may also use QTimer::singleShot(10000, &splash, SLOT(close())); to have some interesting splashscreens even with tiny programs! (Or use Sleep; though that isn't recommended)

chilarai's picture

nice one man

nice one man

Post new comment

The content of this field is kept private and will not be shown publicly. If you have a Gravatar account associated with the e-mail address you provide, it will be used to display your avatar.