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


C++ QCoreApplication::arguments方法代码示例

本文整理汇总了C++中QCoreApplication::arguments方法的典型用法代码示例。如果您正苦于以下问题:C++ QCoreApplication::arguments方法的具体用法?C++ QCoreApplication::arguments怎么用?C++ QCoreApplication::arguments使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在QCoreApplication的用法示例。


在下文中一共展示了QCoreApplication::arguments方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main

int main(int argc, char *argv[]) {
  QCoreApplication app (argc, argv);
 
  CmdLineParser cmd (app.arguments());
  CmdLineParser::Result res = cmd.parse();
  if (res == CmdLineParser::Help)
      return 0;
  else if (res == CmdLineParser::Error)
      return -1;


  QString filename = cmd.file();
  if (!QFile::exists ( filename )) {
    qCritical ("The file you specified doesn't exist!");
    exit (1);
  }
  
  Parser parser;
  bool ok;

  QFile file (filename);
  QVariant data = parser.parse (&file, &ok);
  if (!ok) {
    qCritical("%s:%i - Error: %s", filename.toLatin1().data(), parser.errorLine(), qPrintable(parser.errorString()));
    exit (1);
  }
  else {
    qDebug() << "json object successfully converted to:";
    qDebug() << data;
  }

  if (cmd.serialize()) {
    // serializer tests
    qDebug() << "Serialization output";
    QJson::Serializer serializer;
    serializer.setIndentMode(cmd.indentationMode());
    QByteArray b = serializer.serialize(data);
    qDebug() << b;
  }

  qDebug() << "JOB DONE, BYE";
  return 0;
}
开发者ID:alirezaarmn,项目名称:cutedriver-agent_qt,代码行数:43,代码来源:cmdline_tester.cpp

示例2: applicationPathInfo

AMCrashMonitorSupport::AMCrashMonitorSupport()
{
	errorFile_ = 0;

	QCoreApplication *app = QApplication::instance();

	QStringList applicationArguments = app->arguments();

	QString applicationPath = applicationArguments.at(0);
	QFileInfo applicationPathInfo(applicationPath);

	if(applicationPathInfo.isSymLink())
		pathToCrashReporter_ = applicationPathInfo.symLinkTarget().section('/', 0, -2);
	else
		pathToCrashReporter_ = applicationPathInfo.absoluteDir().path();

	pathToCrashReportFiles_ = "/home/acquaman/AcquamanApplicationCrashReports";

	if(applicationArguments.contains("--enableCrashMonitor")){
		signal(SIGSEGV, handle_signal_sigsev);
		signal(SIGABRT, handle_signal_sigabrt);
	}
}
开发者ID:acquaman,项目名称:acquaman,代码行数:23,代码来源:AMCrashMonitorSupport.cpp

示例3: main

int main (int argc, char *argv[])
{
  QCoreApplication app (argc, argv);

  bool generate_dot = false;
  bool generate_report = false;
  bool no_lines = false;
  bool debug_info = true;
  bool troll_copyright = false;
  QString file_name = 0;

  QStringList args = app.arguments ();
  args.removeFirst ();

  foreach (QString arg, args)
    {
      if (arg == QLatin1String ("-h") || arg == QLatin1String ("--help"))
        help_me ();

      else if (arg == QLatin1String ("-v") || arg == QLatin1String ("--verbose"))
        generate_report = true;

      else if (arg == QLatin1String ("--dot"))
        generate_dot = true;

      else if (arg == QLatin1String ("--no-lines"))
        no_lines = true;

      else if (arg == QLatin1String ("--no-debug"))
        debug_info = false;

      else if (arg == QLatin1String ("--troll"))
        troll_copyright = true;

      else if (file_name.isEmpty ())
	file_name = arg;

      else
        qerr << "*** Warning. Ignore argument `" << arg << "'" << endl;
    }

  if (file_name.isEmpty ())
    {
      help_me ();
      exit (EXIT_SUCCESS);
    }

  Grammar grammar;
  Recognizer p (&grammar, no_lines);

  if (! p.parse (file_name))
    exit (EXIT_FAILURE);

  if (grammar.rules.isEmpty ())
    {
      qerr << "*** Fatal. No rules!" << endl;
      exit (EXIT_FAILURE);
    }

  else if (grammar.start == grammar.names.end ())
    {
      qerr << "*** Fatal. No start symbol!" << endl;
      exit (EXIT_FAILURE);
    }

  grammar.buildExtendedGrammar ();
  grammar.buildRuleMap ();

  Automaton aut (&grammar);
  aut.build ();

  CppGenerator gen (p, grammar, aut, generate_report);
  gen.setDebugInfo (debug_info);
  gen.setTrollCopyright (troll_copyright);
  gen ();

  if (generate_dot)
    {
      DotGraph genDotFile (qout);
      genDotFile (&aut);
    }

  else if (generate_report)
    {
      ParseTable genParseTable (qout);
      genParseTable(&aut);
    }

  return EXIT_SUCCESS;
}
开发者ID:Ipallis,项目名称:Fritzing,代码行数:90,代码来源:main.cpp

示例4: main

int main(int argc, char *argv[]) {
  QCoreApplication app (argc, argv);

#if QT_VERSION < QT_VERSION_CHECK(5,0,0)
  QTextCodec *codec = QTextCodec::codecForName("UTF-8");
  QTextCodec::setCodecForCStrings(codec);
#endif

  QTime time;
  int   duration;

 
  CmdLineParser cmd (app.arguments());
  CmdLineParser::Result res = cmd.parse();
  if (res == CmdLineParser::Help)
      return 0;
  else if (res == CmdLineParser::Error)
      return -1;

  QString filename = cmd.file();
  if (!QFile::exists ( filename )) {
    qCritical ("The file you specified doesn't exist!");
    exit (1);
  }

  Parser parser;
  bool ok;

  QFile file (filename);
  time.start();
  QVariant data = parser.parse (&file, &ok);
  duration = time.elapsed();
  if (!ok) {
    qCritical("%s:%i - Error: %s", filename.toLatin1().data(), parser.errorLine(), qPrintable(parser.errorString()));
    exit (1);
  }
  else {
    qDebug() << "Parsing of" << filename << "took" << duration << "ms";
    if (!cmd.quiet())
      qDebug() << data;
  }

  if (cmd.serialize()) {
    // serializer tests
    qDebug() << "Serializing... ";
    QJson::Serializer serializer;
    serializer.setIndentMode(cmd.indentationMode());
    time.start();
    QByteArray b = serializer.serialize(data, &ok);
    if (!ok) {
      qCritical() << "Serialization failed:" << serializer.errorMessage();
      exit(1);
    } else {
      duration = time.elapsed();
      qDebug() << "Serialization took:" << duration << "ms";
      if (!cmd.quiet())
       qDebug() << b;
    }
  }

  qDebug() << "JOB DONE, BYE";
  return 0;
}
开发者ID:AEtherSurfer,项目名称:robomongo,代码行数:63,代码来源:cmdline_tester.cpp

示例5: main

int main(int pArgC, char *pArgV[])
{
    // Initialise Qt's message pattern

    OpenCOR::initQtMessagePattern();

    // Initialise the plugins path

    OpenCOR::initPluginsPath(pArgV[0]);

    // Create our application

    QCoreApplication *cliApp = new QCoreApplication(pArgC, pArgV);

    // Some general initialisations

    OpenCOR::initApplication();

    // Try to run OpenCOR as a CLI application

    int res;

    if (!OpenCOR::cliApplication(&res)) {
        // OpenCOR isn't meant to be run as a CLI application, so start its GUI
        // version instead

        static const QString DotExe = ".exe";

        if (cliApp->applicationFilePath().right(DotExe.size()) == DotExe) {
            // This is a safeguard from accidentally running a non-renamed (to
            // '.com') CLI version of OpenCOR

            error("the CLI version of "+qAppName()+" has the wrong extension ('.exe' instead of '.com').");

            res = -1;
        } else {
            QString guiAppFilePath = cliApp->applicationDirPath()+QDir::separator()+qAppName()+DotExe;

            if (!QFile::exists(guiAppFilePath)) {
                // We can't find the GUI version of OpenCOR, so...

                error("the GUI version of "+qAppName()+" cannot be found.");

                res = -1;
            } else {
                // We found the GUI version of OpenCOR, so run it with our
                // arguments, minus the first one since it corresponds to the
                // full path to our executable, which we are not interested in

                QStringList appArguments = cliApp->arguments();

                appArguments.removeFirst();

                QProcess().startDetached(guiAppFilePath, appArguments, QProcess().workingDirectory());

                res = 0;
            }
        }
    }

    // Release some memory

    delete cliApp;

    // We are done, so...

    return res;
}
开发者ID:hsorby,项目名称:opencor,代码行数:68,代码来源:main.cpp

示例6: out

bool
parseCommandLine( QCoreApplication& app, QCommandLineParser& parser, CliOptions& options, qint32& profileId,
                  QString& errmsg )
{
    parser.setApplicationDescription( "RedTimer Command Line Interface" );

    // Commands
    QMap<QString,QString> commands;
    commands.insert( "create", "Create a new issue" );
    commands.insert( "issue",  "Get the current issue ID" );
    commands.insert( "start",  "Start issue tracking" );
    commands.insert( "stop",   "Stop issue tracking" );

    QStringList descr;
    QMapIterator<QString, QString> cmd( commands );
    while( cmd.hasNext() )
    {
        cmd.next();

        QString data;
        QTextStream out( &data );
        out.setFieldAlignment( QTextStream::AlignLeft );
        out << qSetFieldWidth(10) << cmd.key() << cmd.value();
        descr.push_back( data );
    }

    parser.addPositionalArgument( "command", descr.join("\n"), "create|issue|start|stop" );

    // Program parameters
    parser.addOption( {"profile-id", "Redmine instance to send the command to", "ID"} );

    // Command parameters
    parser.addOption( {"assignee-id",        "Redmine assignee ID",      "ID"} );
    parser.addOption( {"issue-id",           "Redmine issue ID",         "ID"} );
    parser.addOption( {"parent-id",          "Redmine parent issue ID",  "ID"} );
    parser.addOption( {"project-id",         "Redmine project ID",       "ID"} );
    parser.addOption( {"tracker-id",         "Redmine tracker ID",       "ID"} );
    parser.addOption( {"version-id",         "Redmine version ID",       "ID"} );
    parser.addOption( {"external-id",        "External issue ID",        "text"} );
    parser.addOption( {"external-parent-id", "External parent issue ID", "text"} );
    parser.addOption( {"subject",            "Issue subject",            "text"} );
    parser.addOption( {"description",        "Issue description",        "text"} );

    // General parameters
    parser.addHelpOption();
    parser.addVersionOption();

    // Process command line options
    if( !parser.parse(app.arguments()) )
    {
        errmsg = parser.errorText();
        return false;
    }

    if( parser.isSet("help") )
        return false;


    // Get the command

    const QStringList positionalArguments = parser.positionalArguments();

    if( positionalArguments.isEmpty() )
    {
        errmsg = "No command specified.";
        return false;
    }

    if( positionalArguments.size() > 1 )
    {
        errmsg = "Several commands specified.";
        return false;
    }

    options.command = positionalArguments.first();

    if( commands.find(options.command) == commands.end() )
    {
        errmsg = QString("Command '%1' not found.").arg(options.command);
        return false;
    }

    auto getNumericId = [&]( const QString& option, qint32& id )
    {
        if( !parser.isSet(option) )
            return true;

        QString idString = parser.value( option );
        bool ok;
        id = idString.toInt( &ok );

        if( !ok )
        {
            errmsg = QString("Option '--%1' expects a numeric ID.").arg(option);
            return false;
        }

        return true;
    };

//.........这里部分代码省略.........
开发者ID:fathomssen,项目名称:redtimer,代码行数:101,代码来源:main.cpp

示例7: main

int main( int argc, char **argv )
{
	QCoreApplication* app = nullptr;

#ifdef ITALC_BUILD_LINUX
	// do not create graphical application if DISPLAY is not available
	if( QProcessEnvironment::systemEnvironment().contains( "DISPLAY" ) == false )
	{
		app = new QCoreApplication( argc, argv );
	}
	else
	{
		app = new QApplication( argc, argv );
	}
#else
	app = new QApplication( argc, argv );
#endif

	if( app->arguments().count() < 2 )
	{
		qCritical( "ERROR: not enough arguments - please specify a command" );

		return -1;
	}

	if( app->arguments().last() == "-v" || app->arguments().last() == "--version" )
	{
		printf( "%s\n", ITALC_VERSION );
		return 0;
	}

	ItalcCore* core = new ItalcCore( app, "Control" );

	QMap<CommandLinePluginInterface *, QObject *> commandLinePluginInterfaces;

	for( auto pluginObject : core->pluginManager().pluginObjects() )
	{
		auto commandLinePluginInterface = qobject_cast<CommandLinePluginInterface *>( pluginObject );
		if( commandLinePluginInterface )
		{
			commandLinePluginInterfaces[commandLinePluginInterface] = pluginObject;
		}
	}

	QString command = app->arguments()[1];

	for( auto commandLinePluginInterface : commandLinePluginInterfaces.keys() )
	{
		if( commandLinePluginInterface->commandName() == command )
		{
			CommandLinePluginInterface::RunResult runResult = CommandLinePluginInterface::Unknown;

			if( app->arguments().count() > 2 )
			{
				QString subCommand = app->arguments()[2];

				if( commandLinePluginInterface->subCommands().contains( subCommand ) &&
						QMetaObject::invokeMethod( commandLinePluginInterfaces[commandLinePluginInterface],
												   QString( "handle_%1" ).arg( subCommand ).toLatin1().constData(),
												   Qt::DirectConnection,
												   Q_RETURN_ARG(CommandLinePluginInterface::RunResult, runResult),
												   Q_ARG( QStringList, app->arguments().mid( 3 ) ) ) )
				{
					// runResult contains result
				}
				else
				{
					runResult = commandLinePluginInterface->runCommand( app->arguments().mid( 2 ) );
				}
			}
			else
			{
				runResult = CommandLinePluginInterface::NotEnoughArguments;
			}

			delete core;

			switch( runResult )
			{
			case CommandLinePluginInterface::Successful:
				qInfo( "[OK]" );
				return 0;
			case CommandLinePluginInterface::Failed:
				qInfo( "[FAIL]" );
				return -1;
			case CommandLinePluginInterface::InvalidCommand:
				if( app->arguments().contains( "help" ) == false )
				{
					qCritical( "Invalid subcommand!" );
				}
				qCritical( "Available subcommands:" );
				for( auto subCommand : commandLinePluginInterface->subCommands() )
				{
					qCritical( "    %s - %s", subCommand.toUtf8().constData(),
							   commandLinePluginInterface->subCommandHelp( subCommand ).toUtf8().constData() );
				}
				return -1;
			case CommandLinePluginInterface::InvalidArguments:
				qCritical( "Invalid arguments specified" );
				return -1;
//.........这里部分代码省略.........
开发者ID:iTALC,项目名称:italc,代码行数:101,代码来源:main.cpp

示例8: main

int main ( int argc, char **argv )
{
  QCoreApplication app ( argc, argv );

  QHash<int, QImage> imagesToUse;
  QList<QImage> images;
  const QSize size16 ( 16,16 );
  const QSize size32 ( 32,32 );
  const QSize size48 ( 48,48 );
  if ( argc < 3 )
    usage ( "To few arguments" );

  QString rcFileName;
  QString icoFileName;
  int hotspotx = 0;
  int hotspoty = 0;
  int framerate = 3;
  for ( int i = 1; i < argc; i++ ) {
    const QString arg = app.arguments() [i];
    if ( arg == QLatin1String ( "--rcfile" ) ) {
      if ( i + 1 < argc ) {
        rcFileName = app.arguments() [i+1];
        i++;
        continue;
      } else {
        usage ( "option '--rcfile' without filename" );
      }
    } else if (arg == "--hotspotx") {
       if ( i + 1 < argc ) {
        hotspotx = app.arguments()[i+1].toInt();
        i++;
        continue;
       } else {
        usage ( "option '--hotspotx' without value" );
       }
    } else if (arg == "--hotspoty") {
       if ( i + 1 < argc ) {
        hotspoty = app.arguments()[i+1].toInt();
        i++;
        continue;
    } else {
        usage ( "option '--hotspoty' without value" );
       }
    } else if (arg == "--framerate") {
       if ( i + 1 < argc ) {
        framerate = app.arguments()[i+1].toInt();
        i++;
        continue;
    } else {
        usage ( "option '--framerate' without value" );
       }
    }

    if ( icoFileName.isEmpty() ) {
      icoFileName = arg;
      continue;
    }
    QImage img;
    img.load ( arg );
    if ( img.isNull() ) {
      warning ( QString ( "Can not load image %1" ).arg ( arg ) );
      continue;
    }

    if (icoFileName.endsWith(".ico", Qt::CaseInsensitive)) {
        images += img;
        if ( img.size() == size16 ) {
        if ( imagesToUse.contains ( 16 ) ) {
            warning ( QString ( "Already have an Image with 16x16 - overwriting with %1" ).arg ( arg ) );
        }
        imagesToUse.insert ( 16, img );
        continue;
        }
        if ( img.size() == size32 ) {
        if ( imagesToUse.contains ( 32 ) ) {
            warning ( QString ( "Already have an Image with 32x32 - overwriting with %1" ).arg ( arg ) );
        }
        imagesToUse.insert ( 32, img );
        continue;
        }
        if ( img.size() == size48 ) {
        if ( imagesToUse.contains ( 48 ) ) {
            warning ( QString ( "Already have an Image with 48x48- overwriting with %1" ).arg ( arg ) );
        }
        imagesToUse.insert ( 48, img );
        continue;
        }
    } else {
        if (img.size() != QSize(32, 32)) {
            img = scaleImage(img);
        }

        images += img;
    }
  }
  if ( images.count() == 0 )
    usage ( "No valid images found!" );
  if (icoFileName.endsWith(".ico", Qt::CaseInsensitive)) {
    qSort ( images.begin(), images.end(), sortQImageForSize );
    // 48x48 available -> if not create one
//.........这里部分代码省略.........
开发者ID:KDE,项目名称:digikam-software-compilation,代码行数:101,代码来源:png2ico.cpp


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