Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is "QApplication app(argc, argv)" trying to do?

Tags:

c++

qt

qml

#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 bit rusty. Can someone please explain to me what is "QApplication app(argc, argv)" trying to do ?

Is it trying to declare a function which takes in 2 arguments (argc and argv) and return a variable of type QApplication ?

like image 333
koayst Avatar asked Jul 09 '12 13:07

koayst


People also ask

What does QApplication do?

The QApplication class manages the GUI application's control flow and main settings. QApplication contains the main event loop, where all events from the window system and other sources are processed and dispatched. It also handles the application's initialization, finalization, and provides session management.

What is the purpose of the exec () method of the QApplication class?

[static] int QApplication::exec() Enters the main event loop and waits until exit() is called, then returns the value that was set to exit() (which is 0 if exit() is called via quit()). It is necessary to call this function to start event handling.


1 Answers

The line

QApplication app(argc, argv);

creates a new instance of type QApplication and invokes the constructor of this class. In your example, the variable app now stores this instance. It is somewhat (semantically) a shorthand of this:

QApplication app = QApplication(argc, argv);
like image 52
Constantinius Avatar answered Sep 28 '22 01:09

Constantinius