[QT Development] implements the QT program startup Screen

Source: Internet
Author: User
Tags sleep function qtest

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 .)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.