QApplication app(argc, argv)

心已入冬 提交于 2019-12-06 01:52:21

There are no hidden arguments. You can explicitly see every argument- argc, argv. There's nothing in that line of code that's behind the scenes.

From looking at your comments to other answers, I think you are wondering about arguments passed in to your executable if you don't specify any arguments. I'm not sure if it is standardized or what the exceptions may be, but usually in this case, argc will be 1 and argv[0] will be a string that specifies the command that was used to invoke your executable.

Let's assume your executable is called app and resides in /home/user/appdir.

If your current directory is the applications directory and you launch it with 'app' then argc will be 1 and argv[0] will be app.

If you are one directory up from the application's directory and invoke it with ./appdir/app then argc will be 1 and I believe argv[0] will be appdir/app

If you do specify an argument when invoking your application; perhaps you want to tell your application to output debug information like so app debug. In this case, argc will be 2, argv[0] will be app and argv[1] will be debug.

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.

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

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.

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.

If you are asking what QApplication does with arguments then the answer is in the docs. That page lists the arguments recognised by Qt.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!