什么是“QApplication app(argc, argv)"?想做什么? [英] What is "QApplication app(argc, argv)" trying to do?

查看:46
本文介绍了什么是“QApplication app(argc, argv)"?想做什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

这篇关于什么是“QApplication app(argc, argv)"?想做什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆