本文整理汇总了C++中QCommandLineParser::addOption方法的典型用法代码示例。如果您正苦于以下问题:C++ QCommandLineParser::addOption方法的具体用法?C++ QCommandLineParser::addOption怎么用?C++ QCommandLineParser::addOption使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QCommandLineParser
的用法示例。
在下文中一共展示了QCommandLineParser::addOption方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
app.setApplicationName("objects");
app.setApplicationVersion("0.1");
QCommandLineParser parser;
parser.setApplicationDescription("OpenGL objects");
parser.addHelpOption();
parser.addVersionOption();
QCommandLineOption objectOption(QStringList() << "o" << "object",
QCoreApplication::translate("main", "Use object <object>."),
QCoreApplication::translate("main", "object"),
QString::fromLatin1("earth.obj"));
parser.addOption(objectOption);
QCommandLineOption shaderOption(QStringList() << "s" << "shader",
QCoreApplication::translate("main", "Use shaders <shader>.[fv].glsl."),
QCoreApplication::translate("main", "shader"),
QString::fromLatin1("simple"));
parser.addOption(shaderOption);
parser.process(app);
#ifndef QT_NO_OPENGL
MainWidget widget;
widget.setObject(parser.value(objectOption));
widget.setShader(parser.value(shaderOption));
widget.show();
#else
QLabel note("OpenGL Support required");
note.show();
#endif
return app.exec();
}
示例2: main
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
KAboutData about(QStringLiteral("kapptest"), i18n("kapptest"), QStringLiteral("version"));
KAboutData::setApplicationData(about);
QCommandLineParser options;
options.addOption(QCommandLineOption(QStringList(QStringLiteral("t")) << QStringLiteral("type"), i18n("The type of shutdown to emulate: Default, None, Reboot, Halt or Logout"), QStringLiteral("name"), QStringLiteral("None")));
options.addOption(QCommandLineOption(QStringLiteral("choose"), i18n("Sets the mode where the user can choose between the different options. Use with --type.")));
about.setupCommandLine(&options);
options.process(app);
about.processCommandLine(&options);
KIconLoader::global()->addAppDir(QStringLiteral("ksmserver"));
QString sdtypeOption = options.value(QStringLiteral("type")).toLower();
KWorkSpace::ShutdownType sdtype = KWorkSpace::ShutdownTypeDefault;
if (sdtypeOption == QStringLiteral("reboot")) {
sdtype = KWorkSpace::ShutdownTypeReboot;
} else if (sdtypeOption == QStringLiteral("halt")) {
sdtype = KWorkSpace::ShutdownTypeHalt;
} else if (sdtypeOption == QStringLiteral("logout")) {
sdtype = KWorkSpace::ShutdownTypeNone;
}
QString bopt;
(void)KSMShutdownDlg::confirmShutdown( true, options.isSet(QStringLiteral("choose")), sdtype, bopt, QString() );
/* (void)KSMShutdownDlg::confirmShutdown( false, false, sdtype, bopt ); */
}
示例3: main
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QCommandLineParser parser;
parser.setApplicationDescription("agar.io private server");
parser.addHelpOption();
QCommandLineOption dbgOption(QStringList() << "d" << "debug",
QCoreApplication::translate("main", "Debug output [default: off]."));
parser.addOption(dbgOption);
QCommandLineOption portOption(QStringList() << "p" << "port",
QCoreApplication::translate("main", "Port for server [default: 9000]."),
QCoreApplication::translate("main", "port"), QLatin1Literal("9000"));
parser.addOption(portOption);
parser.process(a);
bool debug = parser.isSet(dbgOption);
int port = parser.value(portOption).toInt();
GameServer *server = new GameServer(port, debug);
QObject::connect(server, &GameServer::closed, &a, &QCoreApplication::quit);
return a.exec();
}
示例4: main
int main(int argc, char **argv)
{
QCoreApplication app(argc, argv);
const QString description = QStringLiteral("Converts desktop files to json");
const char version[] = "1.0";
app.setApplicationVersion(version);
const static QString _i = QStringLiteral("input");
const static QString _o = QStringLiteral("output");
const static QString _n = QStringLiteral("name");
QCommandLineOption input = QCommandLineOption(QStringList() << QStringLiteral("i") << _i,
QStringLiteral("Read input from file"), _n);
QCommandLineOption output = QCommandLineOption(QStringList() << QStringLiteral("o") << _o,
QStringLiteral("Write output to file"), _n);
QCommandLineParser parser;
parser.addVersionOption();
parser.addHelpOption(description);
parser.addOption(input);
parser.addOption(output);
KConfigToJson dtj(&parser, input, output);
parser.process(app);
return dtj.runMain();
}
示例5: main
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
a.setApplicationName(TARGET);
a.setApplicationVersion("1");
#ifdef __linux__
a.setWindowIcon(QIcon(":MoleGraph.png"));
#endif
QCommandLineParser parser;
parser.setApplicationDescription("Test helper");
parser.addHelpOption();
parser.addVersionOption();
QCommandLineOption openOption(QStringList() << "o" << "open-file",
QCoreApplication::translate("main", "Open file."), QCoreApplication::translate("main", "directory"));
parser.addOption(openOption);
QCommandLineOption withoutValuesOption(QStringList() << "w" << "without-values",
QCoreApplication::translate("main", "Modifier for opening file without values (just measurement template)."));
parser.addOption(withoutValuesOption);
parser.addPositionalArgument("file", "file to open");
parser.process(a);
QString fileName = parser.value(openOption);
const QStringList arguments = parser.positionalArguments();
if (arguments.size() > 0)
fileName = arguments[0];
MainWindow w(a, fileName, parser.isSet(withoutValuesOption));
w.show();
return a.exec();
}
示例6: testStdinArgument
void tst_QCommandLineParser::testStdinArgument()
{
QFETCH(QCommandLineParser::SingleDashWordOptionMode, parsingMode);
QCoreApplication app(empty_argc, empty_argv);
QCommandLineParser parser;
parser.setSingleDashWordOptionMode(parsingMode);
parser.addOption(QCommandLineOption(QStringList() << "i" << "input", QStringLiteral("Input file."), QStringLiteral("filename")));
parser.addOption(QCommandLineOption("b", QStringLiteral("Boolean option.")));
QVERIFY(parser.parse(QStringList() << "tst_qcommandlineparser" << "--input" << "-"));
QCOMPARE(parser.value("input"), QString("-"));
QCOMPARE(parser.positionalArguments(), QStringList());
QCOMPARE(parser.unknownOptionNames(), QStringList());
QVERIFY(parser.parse(QStringList() << "tst_qcommandlineparser" << "--input" << "-" << "-b" << "arg"));
QCOMPARE(parser.value("input"), QString("-"));
QVERIFY(parser.isSet("b"));
QCOMPARE(parser.positionalArguments(), QStringList() << "arg");
QCOMPARE(parser.unknownOptionNames(), QStringList());
QVERIFY(parser.parse(QStringList() << "tst_qcommandlineparser" << "-"));
QCOMPARE(parser.value("input"), QString());
QVERIFY(!parser.isSet("b"));
QCOMPARE(parser.positionalArguments(), QStringList() << "-");
QCOMPARE(parser.unknownOptionNames(), QStringList());
}
示例7: createInputCommands
//! Bereitet die Eingabeparameter vor
void createInputCommands(QCommandLineParser &cmdParser) {
//! Befehle
QCommandLineOption inputPath("i", "Path for input", "...");
QCommandLineOption outputPath("o", "Path for output", "...");
QCommandLineOption generateType("g", "Generating type", "[htmlbasic]");
QCommandLineOption chartTitle("t", "Title for the chart", "...");
QCommandLineOption minValueX("x", "Maximumvalue for the chart on the X-Axis", "...");
QCommandLineOption minValueY("y", "Maximumvalue for the chart on the Y-Axis", "...");
cmdParser.setApplicationDescription("Description");
cmdParser.addHelpOption();
cmdParser.addPositionalArgument("useLabel",
"Use the label form json as label for the graph");
cmdParser.addPositionalArgument("useScrolling", "Uses Scrolling with Highstock");
cmdParser.addPositionalArgument("useInlineJS",
"Uses JQuery and HighChart without seperate File");
cmdParser.addPositionalArgument("useNavigator", "Adds a navigator to the chart");
//! Optionen hinzufügen
cmdParser.addOption(inputPath);
cmdParser.addOption(outputPath);
cmdParser.addOption(generateType);
cmdParser.addOption(chartTitle);
cmdParser.addOption(minValueX);
cmdParser.addOption(minValueY);
}
示例8: parse
void ApplicationSettings::parse()
{
QCommandLineParser parser;
parser.setApplicationDescription(QObject::tr("i-score - An interactive sequencer for the intermedia arts."));
parser.addHelpOption();
parser.addVersionOption();
parser.addPositionalArgument("file", QCoreApplication::translate("main", "Scenario to load."));
QCommandLineOption noGUI("no-gui", QCoreApplication::translate("main", "Disable GUI"));
parser.addOption(noGUI);
QCommandLineOption noRestore("no-restore", QCoreApplication::translate("main", "Disable auto-restore"));
parser.addOption(noRestore);
QCommandLineOption autoplayOpt("autoplay", QCoreApplication::translate("main", "Auto-play the loaded scenario"));
parser.addOption(autoplayOpt);
parser.process(*qApp);
const QStringList args = parser.positionalArguments();
tryToRestore = !parser.isSet(noRestore);
gui = !parser.isSet(noGUI);
autoplay = parser.isSet(autoplayOpt) && args.size() == 1;
if(!args.empty() && QFile::exists(args[0]))
{
loadList.push_back(args[0]);
}
}
示例9: main
int main(int argc, char **argv)
{
QApplication app(argc, argv);
KAboutData aboutData(QStringLiteral("test"),
i18n("Test Application"),
QStringLiteral("1.0"));
QCommandLineParser parser;
KAboutData::setApplicationData(aboutData);
parser.addVersionOption();
parser.addHelpOption();
parser.addOption(QCommandLineOption(QStringList() << QStringLiteral("path"), i18n("IMAP destination path"), QStringLiteral("argument")));
parser.addOption(QCommandLineOption(QStringList() << QStringLiteral("mimetype"), i18n("Source mimetype"), QStringLiteral("argument"), QStringLiteral("application/octet-stream")));
parser.addOption(QCommandLineOption(QStringList() << QStringLiteral("file"), i18n("Source file"), QStringLiteral("argument")));
parser.addOption(QCommandLineOption(QStringList() << QStringLiteral("count"), i18n("Number of times this file is added"), QStringLiteral("argument"), QStringLiteral("1")));
//PORTING SCRIPT: adapt aboutdata variable if necessary
aboutData.setupCommandLine(&parser);
parser.process(app);
aboutData.processCommandLine(&parser);
QString path = parser.value(QStringLiteral("path"));
QString mimetype = parser.value(QStringLiteral("mimetype"));
QString file = parser.value(QStringLiteral("file"));
int count = qMax(1, parser.value(QStringLiteral("count")).toInt());
ItemDumper d(path, file, mimetype, count);
return app.exec();
}
示例10: main
int main(int argc, char** argv)
{
if( loadSettingsOk(argc, argv) )
{
// If -l option is provided, settings are loaded and app is closed.
QCoreApplication app(argc, argv);
LoadSettings load;
return app.exec();
}
LXQt::SingleApplication app(argc, argv);
// Command line options
QCommandLineParser parser;
QCommandLineOption loadOption(QStringList() << "l" << "loadlast",
app.tr("Load last settings."));
parser.addOption(loadOption);
QCommandLineOption helpOption = parser.addHelpOption();
parser.addOption(loadOption);
parser.addOption(helpOption);
//parser.process(app);
//bool loadLastSettings = parser.isSet(loadOption);
MonitorSettingsDialog dlg;
app.setActivationWindow(&dlg);
dlg.setWindowIcon(QIcon::fromTheme("preferences-desktop-display"));
dlg.show();
return app.exec();
}
示例11: main
int main(int argc, char *argv[])
{
QCoreApplication app(argc, argv);
// some command line arguments parsing stuff
QCoreApplication::setApplicationName("ujea");
QCoreApplication::setApplicationVersion("1.2");
QString hostname = QHostInfo::localHostName();
QCommandLineParser parser;
parser.setApplicationDescription("Universal job execution agent using AMQP queue");
parser.addHelpOption();
parser.addVersionOption();
parser.addOption(QCommandLineOption("aliveInterval", "Interval in ms between alive messages (1000).", "aliveInterval", "1000"));
parser.addOption(QCommandLineOption("aliveTTL", "TTL in queue for alive messages (1500).", "aliveTTL", "1500"));
parser.addOption(QCommandLineOption("queueCmd", "Commands queue name ("+hostname+"_cmd).", "queueCmd", hostname+"_cmd"));
parser.addOption(QCommandLineOption("queueRpl", "Replays queue name ("+hostname+"_rpl).", "queueRpl", hostname+"_rpl"));
parser.addOption(QCommandLineOption("execRegex", "Regex for permited commands. (none)", "execRegex", ""));
parser.addPositionalArgument("url", QCoreApplication::translate("main", "AMQP url"));
parser.process(app);
const QStringList args = parser.positionalArguments();
// we need to have 1 argument and optional named arguments
if (args.count() != 1) parser.showHelp(-1);
// create and execure worker
JobsExecuter qw{QUrl(args.value(0)), parser.value("queueCmd"), parser.value("queueRpl"),
parser.value("aliveInterval").toInt(), parser.value("aliveTTL").toInt(),
parser.value("execRegex")};
return app.exec();
}
示例12: main
QT_USE_NAMESPACE
int main(int argc, char **argv)
{
QGuiApplication app(argc, argv);
QCoreApplication::setApplicationName(QStringLiteral("qtdiag"));
QCoreApplication::setApplicationVersion(QLatin1String(QT_VERSION_STR));
QCoreApplication::setOrganizationName(QStringLiteral("QtProject"));
QCoreApplication::setOrganizationDomain(QStringLiteral("qt-project.org"));
QCommandLineParser commandLineParser;
const QCommandLineOption noGlOption(QStringLiteral("no-gl"), QStringLiteral("Do not output GL information"));
const QCommandLineOption glExtensionOption(QStringLiteral("gl-extensions"), QStringLiteral("List GL extensions"));
const QCommandLineOption fontOption(QStringLiteral("fonts"), QStringLiteral("Output list of fonts"));
commandLineParser.setApplicationDescription(QStringLiteral("Prints diagnostic output about the Qt library."));
commandLineParser.addOption(noGlOption);
commandLineParser.addOption(glExtensionOption);
commandLineParser.addOption(fontOption);
commandLineParser.addHelpOption();
commandLineParser.process(app);
unsigned flags = commandLineParser.isSet(noGlOption) ? 0u : unsigned(QtDiagGl);
if (commandLineParser.isSet(glExtensionOption))
flags |= QtDiagGlExtensions;
if (commandLineParser.isSet(fontOption))
flags |= QtDiagFonts;
std::wcout << qtDiag(flags).toStdWString();
return 0;
}
示例13: main
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QCoreApplication::setApplicationName("empire-gui");
// Configure parser for command line arguments
QCommandLineParser parser;
parser.setSingleDashWordOptionMode(QCommandLineParser::ParseAsLongOptions);
parser.addHelpOption();
QCommandLineOption modeOption("obs", "Start the client as observer.");
parser.addOption(modeOption);
QCommandLineOption addressOption("saddr", "Server address.", "port", "localhost");
parser.addOption(addressOption);
QCommandLineOption portOption("sport", "Server port.", "port", "0");
parser.addOption(portOption);
// Get arguments values
parser.process(a);
MainWindow w;
// Process arguments
QStringList args = parser.positionalArguments();
QString address = parser.value("saddr");
int port = parser.value("sport").toInt();
w.initialize(address, port, parser.isSet(modeOption));
w.show();
return a.exec();
}
示例14: parse
ParsedInfo parse(const QStringList & argv)
{
QCommandLineParser parser;
parser.addHelpOption();
parser.addVersionOption();
parser.addPositionalArgument( "input-files", "list of files to open", "[input files]");
QCommandLineOption configFileOption(
{ "config", "cfg"}, "config file path", "configFilePath");
parser.addOption( configFileOption);
QCommandLineOption htmlPathOption(
"html", "development option for desktop version, path to html to load", "htmlPath"
);
parser.addOption( htmlPathOption);
QCommandLineOption scriptPortOption(
"scriptPort", "port on which to listen for scripted commands", "scriptPort");
parser.addOption( scriptPortOption);
// Process the actual command line arguments given by the user, exit if
// command line arguments have a syntax error, or the user asks for -h or -v
parser.process( argv);
// try to get config file path from command line
ParsedInfo info;
info.m_configFilePath = parser.value( configFileOption);
// if command line was not used to set the config file path, try environment var
if( info.m_configFilePath.isEmpty()) {
info.m_configFilePath = cartaGetEnv( "CONFIG");
}
// if the config file was not specified neither through command line or environment
// assign a default value
if( info.m_configFilePath.isEmpty()) {
info.m_configFilePath = QDir::homePath() + "/.cartavis/config.json";
}
// get html path
if( parser.isSet( htmlPathOption)) {
info.m_htmlPath = parser.value( htmlPathOption);
}
// get script port
if( parser.isSet( scriptPortOption)) {
QString portString = parser.value( scriptPortOption);
bool ok;
info.m_scriptPort = portString.toInt( & ok);
if( ! ok || info.m_scriptPort < 0 || info.m_scriptPort > 65535) {
parser.showHelp( -1);
}
}
qDebug() << "script port=" << info.scriptPort();
// get a list of files to open
info.m_fileList = parser.positionalArguments();
qDebug() << "list of files to open:" << info.m_fileList;
return info;
}
示例15: parseCommandLine
CommandLineParameters parseCommandLine(const QStringList &arguments)
{
QCommandLineParser parser;
parser.setApplicationDescription(QObject::tr("Zeal - Offline documentation browser."));
parser.addHelpOption();
parser.addVersionOption();
/// TODO: [Qt 5.4] parser.addOption({{"f", "force"}, "Force the application run."});
parser.addOption(QCommandLineOption({QStringLiteral("f"), QStringLiteral("force")},
QObject::tr("Force the application run.")));
/// TODO: [0.2.0] Remove --query support
parser.addOption(QCommandLineOption({QStringLiteral("q"), QStringLiteral("query")},
QObject::tr("[DEPRECATED] Query <search term>."),
QStringLiteral("term")));
#ifdef Q_OS_WIN32
parser.addOption(QCommandLineOption({QStringLiteral("register")},
QObject::tr("Register protocol handlers")));
parser.addOption(QCommandLineOption({QStringLiteral("unregister")},
QObject::tr("Unregister protocol handlers")));
#endif
parser.addPositionalArgument(QStringLiteral("url"), QObject::tr("dash[-plugin]:// URL"));
parser.process(arguments);
CommandLineParameters clParams;
clParams.force = parser.isSet(QStringLiteral("force"));
#ifdef Q_OS_WIN32
clParams.registerProtocolHandlers = parser.isSet(QStringLiteral("register"));
clParams.unregisterProtocolHandlers = parser.isSet(QStringLiteral("unregister"));
if (clParams.registerProtocolHandlers && clParams.unregisterProtocolHandlers) {
QTextStream(stderr) << QObject::tr("Parameter conflict: --register and --unregister.\n");
::exit(EXIT_FAILURE);
}
#endif
if (parser.isSet(QStringLiteral("query"))) {
clParams.query.setQuery(parser.value(QStringLiteral("query")));
} else {
/// TODO: Support dash-feed:// protocol
const QString arg
= QUrl::fromPercentEncoding(parser.positionalArguments().value(0).toUtf8());
if (arg.startsWith(QLatin1String("dash:"))) {
clParams.query.setQuery(stripParameterUrl(arg, QStringLiteral("dash")));
} else if (arg.startsWith(QLatin1String("dash-plugin:"))) {
const QUrlQuery urlQuery(stripParameterUrl(arg, QStringLiteral("dash-plugin")));
const QString keys = urlQuery.queryItemValue(QStringLiteral("keys"));
if (!keys.isEmpty())
clParams.query.setKeywords(keys.split(QLatin1Char(',')));
clParams.query.setQuery(urlQuery.queryItemValue(QStringLiteral("query")));
} else {
clParams.query.setQuery(arg);
}
}
return clParams;
}