In our [GC9-2], pro has an instruction, as follows
Defines + = QT predicted warnings defines compilation options
The meaning of this is as follows
This is when I use QTest, the original usage is to add
CONFIG += qtestlib
Display his prompt that I need to use the following
QT += testlib
Now let's go to the main topic of today and add a startup screen to our program. The purpose of this startup screen is to load multiple files when the program starts. These files will be time-consuming. At this time, the user may mistakenly think that the program is not started. Therefore, adding a startup animation can tell the user that the program is started and some modules are being loaded. The effect picture is as follows. The trademark of Geely is used here.
Here we need to use a new thing called QSplashScreen class. For more information about this class, please go here. https://doc.qt.io/qt-5/qsplashscreen.html
The code I use here is relatively simple, as follows
Because my program is relatively simple, so I use Qtest, so I need to include testlib in the pro file. At present, the entire pro file is as follows
QT += core gui testlib #Indicates the Qt module to be introduced greaterThan(QT_MAJOR_VERSION,4):QT += widgets #Designed for Qt4 compatibility, to the effect that the version higher than Qt4 needs to include the widgets module TARGET = GC9.1.0.0 #Program name TEMPLATE = app #Program type DEFINES += QT_DEPRECATED_WARNINGS #Define compile route RC_ICONS = ./Resources/Images/Core/LOGO.ico #Program icon file SOURCES += \ #source file Core/main.cpp \ ControlPanel/controlpanel.cpp \ HUD/hud.cpp FORMS += \ #Interface file ControlPanel/controlpanel.ui \ HUD/hud.ui HEADERS += \ #Header file ControlPanel/controlpanel.h \ HUD/hud.h RESOURCES += \ #resource file resources.qrc
If you use while loop to implement, you don't need to include testlib module.
Next, it is implemented in main.cpp. The code is as follows
#include"ControlPanel/controlpanel.h" #include <QApplication> #include <QSplashScreen> #include <QPixmap> #include <QTest> int main(int argc, char *argv[]) { QApplication a(argc, argv); QPixmap lodingPix(":/Core/Resources/Images/Core/login.png"); //Build pix image object QSplashScreen splash(lodingPix); //Create qsflashscreen object splash.show(); //Show qsflashscreen a.processEvents(); //The general idea is to put the time-consuming load out and run it in a thread. QTest::qSleep(3000); //Increase program display time ControlPanel w; //Establish console main interface w.show(); //start default console splash.finish(&w); //Qsflashscreen end return a.exec(); }
The above completes the adding of program start animation
2019/07/20 15:53