What is a "QApplication (argc, argv) application" trying to do?
#include <QtGui/QApplication> #include <QtDeclarative> #include "qmlapplicationviewer.h" int main(int argc, char **argv) { QApplication app(argc, argv); QmlApplicationViewer viewer; viewer.setMainQmlFile("app/native/assets/main.qml"); viewer.showFullScreen(); return app.exec(); } My C ++ is a little rusty. Can someone explain to me what the “QApplication (argc, argv) application” is trying to do?
Is this an attempt to declare a function that takes 2 arguments (argc and argv) and returns a variable of type QApplication?
Here is a quote from Qt Docs:
The QApplication class controls the flow of control over GUI applications and basic settings.
QApplication contains the main event loop, where all events from the window system and other sources are processed and sent. It also handles initialization, termination, and session management. In addition, QApplication handles most of the system-wide and system-wide settings.
For any GUI application using Qt, there is only one QApplication application object, regardless of whether the application has 0, 1, 2 or more windows at any given time. For applications other than the Qt GUI, use QCoreApplication instead, as this is independent of the QtGui library.
The QApplication object is accessible through the instance () function, which returns a pointer equivalent to the qApp global pointer.
So the line
QApplication app(argc, argv);
creates an instance of the QApplication class.
QApplication is a Qt class that contains the main event loop.
When you write QApplication app(argc, argv); you create an app object of this class by calling its constructor with argc and argv
When int main(int argc, char **argv) is called during program startup, int argc initialized to contain the number of arguments passed at program startup. char **argv contains an array of arguments passed to the program when it was executed.
char * argv [0] will contain (indicate) the name of the program, and subsequent elements will indicate the remaining arguments passed.
argc and argv, in turn, are passed to the QApplication constructor, so when you run your program, you can pass specific arguments to Qt.
For an example of such arguments, try running ./yourProgramName --help in a terminal window
app () is not a function, it is a constructor call.
If you came from C # or Java or something else, imagine this
QApplication app = new QApplication( argc, argv ); It’s just that this application will be a pointer in this way, while in fact it is the object itself, if it is created, as in your example.
In short, Qt needs a QApplication instance to run, so the slots are processed and processed (if you use them) and events such as drawing, etc. are processed.