找回密码
 立即注册
收起左侧

新人问一个小白问题,没有传入参数,怎么程序还运行了?

4
回复
8542
查看
[复制链接]
累计签到:10 天
连续签到:3 天
来源: 2021-1-1 21:15:13 显示全部楼层 |阅读模式
1Qter豆

#include <QApplication>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    return a.exec();
}


在QApplication函数里没有传入具体的argc, argv,实例化的a为什么能正常运行?

回复

使用道具 举报

累计签到:6 天
连续签到:1 天
2021-1-2 15:09:01 显示全部楼层
因为main函数有默认参数
回复

使用道具 举报

累计签到:10 天
连续签到:3 天
2021-1-3 18:22:11 显示全部楼层
设置断点可以看到argc 值是1,argv 值是 <1个项>,不知道什么意思。

点评

argc=1表示程序运行时有1个参数。argv的值是1个项,其实就是程序自身,比如,如果程序是a.exe,其所在路径为c:\mydir,那么argv的值就是“c:\mydir\a.exe”。  详情 回复 发表于 2021-1-7 09:05
回复

使用道具 举报

累计签到:41 天
连续签到:1 天
2021-1-7 09:05:07 显示全部楼层
xmzhang 发表于 2021-1-3 18:22
设置断点可以看到argc 值是1,argv 值是 ,不知道什么意思。

argc=1表示程序运行时有1个参数。argv的值是1个项,其实就是程序自身,比如,如果程序是a.exe,其所在路径为c:\mydir,那么argv的值就是“c:\mydir\a.exe”。
回复

使用道具 举报

累计签到:10 天
连续签到:3 天
2021-1-7 20:03:17 显示全部楼层
多谢,其实还是不太理解,是不是在命令行运行时,用来传入 -t -o之类命令用的?main()函数能运行是因为Qt的缘故

帮助里对参数的解释,尽管也还是看不太懂

QApplication:Application(int &argc, char **argv)
Initializes the window system and constructs an application object with argc command line arguments in argv.
Warning: The data referred to by argc and argv must stay valid for the entire lifetime of the QApplication object. In addition, argc must be greater than zero and argv must contain at least one valid character string.
The global qApp pointer refers to this application object. Only one application object should be created.
This application object must be constructed before any paint devices (including widgets, pixmaps, bitmaps etc.).
Note: argc and argv might be changed as Qt removes command line arguments that it recognizes.
All Qt programs automatically support the following command line options:
-style= style, sets the application GUI style. Possible values depend on your system configuration. If you compiled Qt with additional styles or have additional styles as plugins these will be available to the -style command line option. You can also set the style for all Qt applications by setting the QT_STYLE_OVERRIDE environment variable.
-style style, is the same as listed above.
-stylesheet= stylesheet, sets the application styleSheet. The value must be a path to a file that contains the Style Sheet.
Note: Relative URLs in the Style Sheet file are relative to the Style Sheet file's path.
-stylesheet stylesheet, is the same as listed above.
-widgetcount, prints debug message at the end about number of widgets left undestroyed and maximum number of widgets existed at the same time
-reverse, sets the application's layout direction to Qt::RightToLeft
-qmljsdebugger=, activates the QML/JS debugger with a specified port. The value must be of format port:1234[,block], where block is optional and will make the application wait until a debugger connects to it.
See also QCoreApplication::arguments().
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

公告
可以关注我们的微信公众号yafeilinux_friends获取最新动态,或者加入QQ会员群进行交流:190741849、186601429(已满) 我知道了