当前位置: 首页>>代码示例>>C++>>正文


C++ QCommandLineParser::addOption方法代码示例

本文整理汇总了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();
}
开发者ID:daniel-j-h,项目名称:home,代码行数:35,代码来源:main.cpp

示例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 ); */
}
开发者ID:cmacq2,项目名称:plasma-workspace,代码行数:30,代码来源:test.cpp

示例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();
}
开发者ID:Laity10,项目名称:agar.io-private-server,代码行数:25,代码来源:main.cpp

示例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();
}
开发者ID:crayonink,项目名称:calligra-2,代码行数:29,代码来源:main.cpp

示例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();
}
开发者ID:e-Mole,项目名称:MoleGraph,代码行数:35,代码来源:main.cpp

示例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());
}
开发者ID:SchleunigerAG,项目名称:WinEC7_Qt5.3.1_Fixes,代码行数:26,代码来源:tst_qcommandlineparser.cpp

示例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);
}
开发者ID:LepelTsmok,项目名称:GoogleBench2HighChart,代码行数:27,代码来源:Commandline.cpp

示例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]);
    }
}
开发者ID:himito,项目名称:i-score,代码行数:29,代码来源:ApplicationSettings.cpp

示例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();
}
开发者ID:KDE,项目名称:akonadi,代码行数:28,代码来源:itemdumper.cpp

示例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();

}
开发者ID:jubalh,项目名称:lxqt-config,代码行数:32,代码来源:main.cpp

示例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();
}
开发者ID:kanocz,项目名称:ujea,代码行数:34,代码来源:main.cpp

示例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;
}
开发者ID:2gis,项目名称:2gisqt5android,代码行数:30,代码来源:main.cpp

示例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();
}
开发者ID:a-laine,项目名称:empire-gui,代码行数:30,代码来源:main.cpp

示例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;
}
开发者ID:Astroua,项目名称:CARTAvis,代码行数:59,代码来源:CmdLine.cpp

示例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;
}
开发者ID:haugerbr,项目名称:zeal,代码行数:57,代码来源:main.cpp


注:本文中的QCommandLineParser::addOption方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。