ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
[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(); } ```