我可以获取 Qt 未使用的所有命令行参数吗?
Can I get all command line arguments that are not used by Qt?
我正在开发一个我想接受命令行参数的 Qt 应用程序。
我不想将 QCommandLineParser
与 QCommandLineOptions
一起使用,因为它不支持像内置 argparse
这样的选择,并且因为它需要初始化 QApplication
之前 QCommandLineParser
.
但是,我不能简单地使用 sys.argv
中的参数,因为它们也包含 Qt 特定的参数,例如 --style
。
Qt 是否有一个内置函数来给我这些 Qt 本身不使用的参数,或者我必须自己一个一个地过滤掉它们?
我确实找到了 QCoreApplication.arguments()
,但这不符合我的需要。引自 the docs:
On Unix, this list is built from the argc and argv parameters passed to the constructor in the main() function
据此,我推断 QCoreApplication.arguments
返回的参数列表仍然包含 Qt 特定的选项,例如 --style
.
根据评论,代码...
app = QApplication(sys.argv)
将从 sys.argv
中删除已识别的参数,之后您可以根据需要对 sys.argv
执行自己的处理。
请注意,虽然 python
文档中似乎没有明确说明 c++
docs. 状态...
Note: argc and argv might be changed as Qt removes command line arguments that it recognizes.
我正在开发一个我想接受命令行参数的 Qt 应用程序。
我不想将 QCommandLineParser
与 QCommandLineOptions
一起使用,因为它不支持像内置 argparse
这样的选择,并且因为它需要初始化 QApplication
之前 QCommandLineParser
.
但是,我不能简单地使用 sys.argv
中的参数,因为它们也包含 Qt 特定的参数,例如 --style
。
Qt 是否有一个内置函数来给我这些 Qt 本身不使用的参数,或者我必须自己一个一个地过滤掉它们?
我确实找到了 QCoreApplication.arguments()
,但这不符合我的需要。引自 the docs:
On Unix, this list is built from the argc and argv parameters passed to the constructor in the main() function
据此,我推断 QCoreApplication.arguments
返回的参数列表仍然包含 Qt 特定的选项,例如 --style
.
根据评论,代码...
app = QApplication(sys.argv)
将从 sys.argv
中删除已识别的参数,之后您可以根据需要对 sys.argv
执行自己的处理。
请注意,虽然 python
文档中似乎没有明确说明 c++
docs. 状态...
Note: argc and argv might be changed as Qt removes command line arguments that it recognizes.