gpt4 book ai didi

windows - QStringList QCoreApplication::arguments() - 在什么情况下索引 0 不是 Windows 中的应用程序路径?

转载 作者:可可西里 更新时间:2023-11-01 11:22:21 25 4
gpt4 key购买 nike

QStringList QCoreApplication::arguments() (Qt) 的文档指出:

Usually arguments().at(0) is the program name, arguments().at(1) is the first argument, and arguments().last() is the last argument. See the note below about Windows.

进一步阐述:

On Windows, [...] the arguments() are constructed from the return value of GetCommandLine(). As a result of this, the string given by arguments().at(0) might not be the program name on Windows, depending on how the application was started.

关于最后一个粗体部分,我很好奇这适用于哪种情况。Qt 文档没有解释它,GetCommandLine 也没有解释。的 (WINAPI) 文档。

最佳答案

当您的程序通过 CreateProcess 生成时,可能会发生这种情况- 查看lpCommandLine 参数的说明。基本上,由调用 CreateProcess 的程序来填充第一个参数,因此可能会出现未以通常方式填充值的情况。

来自链接:

"如果lpApplicationName和lpCommandLine都非NULL,则lpApplicationName指向的以null结尾的字符串指定要执行的模块,lpCommandLine指向的以null结尾的字符串指定命令行。新进程可以使用GetCommandLine检索整个命令行。用 C 编写的控制台进程可以使用 argc 和 argv 参数来解析命令行。因为 argv[0] 是模块名称,所以 C 程序员通常将模块名称重复为命令行中的第一个标记”

同样,如果您的程序是使用 spawn 从另一个程序启动的,则可能会发生这种情况。函数族。在那里,文档指出:

“至少有一个参数,arg0 或 argv[0],必须传递给子进程。按照惯例,这个参数是路径名参数的副本。但是,不同的值不会产生错误。”

关于windows - QStringList QCoreApplication::arguments() - 在什么情况下索引 0 不是 Windows 中的应用程序路径?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3304845/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com