In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
Editor to share with you how to develop QT application welcome interface, I believe that most people do not know much about it, so share this article for your reference, I hope you will learn a lot after reading this article, let's go to know it!
The main interface starts too slowly, which usually takes more than 10 seconds, so I want to add a welcome interface and wait for the program to load before displaying the main interface.
The main interface (class named MainWindow) starts slowly because the constructor needs to perform a lot of initialization work.
Create the Welcome class as the welcome interface, starting with creating an object of the Welcome class in the main function, and then show (). For the main interface, call your own show () method when the constructor is about to return, and call welcome's close (). But the welcome interface always shows only borders, no content, and the background of the form is virtual.
Cause analysis:
In QT, the distribution of various events of the form is done by QApplication. In the main function, the last line of code is to call the exec () method of the QApplication object. After this method is executed, the events of the entire application can be distributed and handled. But in the main function, when you create a MainWindow instance, you always wait for the constructor of MainWindow to finish before executing the exec () method of the QApplication object. So before the welcome interface events are not responded, the paintEvent () function will not be executed, so it will not be displayed normally, when the MainWindow constructor is completed, the QApplication object can handle event distribution, there is no need for the welcome interface display, you can directly display the main interface.
We can only find a way to get the constructor of MainWindow to return immediately, leaving the initialization work for later processing. But who will call the initialization work code, the welcome class constructor can not call it, otherwise it will be very slow to display. My approach is to use QTimer for a short period of time to automatically trigger the execution of the initialization code, so that it does not take up the execution time of the constructor and allows QApplication to work as soon as possible.
Here is the abbreviated code:
Main.cpp
Int main (int argc, char * argv []) {QApplication app (argc, argv); / /. Other codes WelcomeWindow * welcome=new WelcomeWindow (); MainWindow w (welcome); return app.exec ();}
Constructor of MainWindow
This- > welcome=welcome;if (welcome! = 0) {welcome- > show (); timerInit=new QTimer (); timerInit- > setInterval (100); timerInit- > setSingleShot (true); / / set Timer to trigger timerInit- > start () only once; connect (timerInit, SIGNAL (timeout ()), SLOT (init ();} else {init ();}
The init () function of MainWindow (put the initialization code of the original constructor in init ())
If (welcome estrangement 0) {welcome- > close (); delete welcome; this- > show ();} these are all the contents of the article "how QT develops the Welcome Interface for applications". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.