🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
[TOC] ## 概述 1. Qt 制作命令行工具时,使用 ## 示例 ``` #include <QCoreApplication> #include <QCommandLineParser> #include <QDebug> int main(int argc, char* argv[]) { QCoreApplication app(argc, argv); QCoreApplication::setApplicationName("MyApp"); QCoreApplication::setApplicationVersion("1.0"); QCommandLineParser parser; parser.setApplicationDescription("A simple command-line application."); parser.addHelpOption(); parser.addVersionOption(); QCommandLineOption verboseOption("verbose", "Enable verbose mode."); parser.addOption(verboseOption); QCommandLineOption output({ "o", "output" }, "echo hello world", "file"); parser.addOption(output); parser.process(app); //判断参数是否开启 if (parser.isSet(verboseOption)) { qDebug() << "Verbose mode is enabled."; } else { qDebug() << "Verbose mode is disabled."; } if (parser.isSet(output)) { qDebug() << "output mode is enabled."; } else { qDebug() << "output mode is disabled."; } return app.exec(); } ```