QApplication app(argc, argv) [英] QApplication app(argc, argv)

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

问题描述

我注意到 Qt 应用程序中的 main.cpp 必须包含以下行:

I noticed that the main.cpp in a Qt application has to contain the following line:

QApplication app(argc, argv);

我知道 argc 是命令行参数的数量,而 argv 是命令行参数的数组列表.但是,我心中的问题是:我传递给构造函数但同时无法明确看到的那些参数是什么?幕后的工作是什么?

I know that argc is the number of command-line arguments, and argv is that array list of command-line arguments. But, the question in my mind is: what are those arguments I'm passing to the constructor and at the same time cannot explicitly see? What is working behind the scences out there?

谢谢.

推荐答案

Qt 应用程序支持一些命令行参数.例如 app.exe -stylemotif 在 Windows 上很有趣.基本上,在这个构造函数中,您将参数传递给 QApplication 类以便解析它们.

Qt applications supports some command line arguments. For example app.exe -style motif on Windows is funny. Basically, in this constructor, you pass the arguments to the QApplication class in order they to be parsed.

当然,您可以自由地向 QApplication 传递任何内容,如下所示:

And of course you are free to pass nothing to QApplication, like this:

int c=1;char** v = &argv[0];QApplication app(c,v); 所以 Qt 不会解析任何东西,也不会接受任何命令行参数.

int c=1; char** v = &argv[0]; QApplication app(c,v); so Qt won't parse anything and won't accept any command line arguments.

关于 argc 和 argv 范围,如果您将其传递给 QApplication,您可以从任何您想要的点访问它们.如果您不将它们传递给 QApplication,您必须小心地将它们设为全局.

About argc and argv scope, if you pass then to QApplication you can access them from every point you want. If you don't pass them to QApplication, you have to take care yourself making them global.

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

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