IfProgramFor example, if you need to load a large amount of data in advance, the program generally has a startup screen. In this way, the user can see that the program is being started rather than simply waiting for it. It also displays some useful information about the program, such as the Program Logo, function module, or product information.
In the QT application, you can use the qsplashscreen class to start the screen. The following is a simple example to load the splash image and pre-load some module data of the program while displaying the image.
Int main (INT argc, char * argv []) {qapplication A (argc, argv); // set the default character encoding qtextcodec * Tc = qtextcodec :: codecforname ("UTF-8"); qtextcodec: setcodecfortr (TC); // load and display the startup screen qsplashscreen splash (qpixmap (":/images/splash.png ")); splash. setdisabled (true); // disable splash for user input event response. show (); splash. showmessage (qobject: TR ("Memory Database Manager. starting .... "), QT: alignleft | QT: alignbottom, QT: Green); // create mainwindow W; splash. showmessage (qobject: TR ("loading module data .... "), QT: alignleft | QT: alignbottom, QT: Green); // after the program data is loaded, display the main view and end the startup screen W. show (); splash. finish (& W); Return a.exe C ();}
If you want to customize the time when the startup screen exists, you can use the qtime or qelapsedtimer class to implement program waiting. As shown in the following figure, the program loops for 1 s in an empty loop:
Qelapsedtimer t; T. Start (); While (T. elapsed () <1000) {qcoreapplication: processevents ();}
(QT does not provide cross-platform sleep functions. If you want to use the sleep function, you can use the qsleep function provided by the qtest class. In fact, qtest actually uses qelapsedtimer .)