Explanation of the main function of QT

Explanation of the main function of QT

Explanation of the main function of QT

After using QT Creator to create a new project (select QDialog as the base class as an example), a default main.cpp file will be generated

#include "dialog.h"

#include <QApplication>

int main(int argc, char *argv[])
{
    
    
    QApplication a(argc, argv);
    Dialog w;
    w.show();
    return a.exec();
}

#include “dialog.h”

Contains the definition of the Dialog class to complete the function in the program, and encapsulates the required functions in the Dialog class.

#include

Every graphical application using QT must use a QApplication object. QApplication manages a wide range of resources, basic settings, control flow, and event handling for a variety of graphical applications.

int main(int argc, char argv[])

The application is empty, and in almost all cases where QT is used, the main() function only needs to perform initialization before transferring control to the QT library, and then the QT library informs the program of the user's behavior through events. There must be one and only one main() function in all QT programs. argc
The number of command-line variables, *argv[]an array of command-line variables.

QApplication a(argc, argv)

a is the program's QApplication object. A QApplication object must be created before any QT window system components are used.

w.show();

The created widget must call the show() function to make it visible, and it is invisible by default.

return a.exec();

The program enters a message loop, waiting for possible input to respond to. The main() function here transfers control to QT. In exec()
Qt receives and processes user and system events and passes them on to the appropriate widgets.

Guess you like

Origin blog.csdn.net/m0_45463480/article/details/130433820