什么是“QApplication app(argc, argv)"?想做什么?

2022-01-19 00:00:00 qt qml c++
#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();
}

我的 C++ 有点生疏了.有人可以向我解释一下QApplication app(argc, argv)"在做什么吗?

My C++ is a bit rusty. Can someone please explain to me what is "QApplication app(argc, argv)" trying to do ?

它是否试图声明一个接受 2 个参数(argc 和 argv)并返回 QApplication 类型的变量的函数?

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

推荐答案

QApplication app(argc, argv);

创建一个 QApplication 类型的新实例并调用该类的构造函数.在您的示例中,变量 app 现在存储此实例.它有点(语义上)是这个的简写:

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);

相关文章