

Process the actual command line arguments given by the userĬonst QStringList args = parser. "), QCoreApplication ::translate( "main", "directory")) A boolean option with multiple names (-f, -force) QCommandLineOption forceOption( QStringList(). A boolean option with a single name (-p) QCommandLineOption showProgressOption( "p", QCoreApplication ::translate( "main", "Show progress during copy")) addPositionalArgument( "destination", QCoreApplication ::translate( "main", "Destination directory.")) addPositionalArgument( "source", QCoreApplication ::translate( "main", "Source file to copy.")) setApplicationDescription( "Test helper") QCoreApplication ::setApplicationVersion( "1.0") QCoreApplication ::setApplicationName( "my-copy-program") However, it is possible to handle this case explicitly by making an option with no-option as one of its names, and handling the option explicitly. The parser does not automatically support negating or disabling long options by using the format -disable-option or -no-option. If such an option is placed last and has no value, the option will be treated as if it had not been specified. The parser does not support optional values - if an option is set to require a value, one must be present. the next argument is used as value (even if it starts with a -). Passing values to options can be done using the assignment operator: -v=value -verbose=value, or a space: -v value -verbose value, i.e. The long option verbose would be passed as -verbose or -verbose. Long options are more than one letter long and cannot be compacted together. The parsing mode for can be set to ParseAsLongOptions, in which case -abc will be parsed as the long option abc. In the default parsing mode, short options can be written in a compact form, for instance -abc is equivalent to -a -b -c. The option v would be specified by passing -v on the command line. The parser will treat everything after the option - (double dash) as positional arguments. The option - (single dash alone) is a special case, often meaning standard input, and not treated as an option. Options on the command line are recognized as starting with a single or double - character(s). The parser handles short names, long names, more than one name for the same option, and option values. doesn't start with a -) is stored as a "positional argument". QCommandLineParser provides the ability to define a set of options, parse the command-line arguments, and store which options have actually been used, as well as option values.Īny argument that isn't an option (i.e. QCoreApplication provides the command-line arguments as a simple list of strings. Values(const QCommandLineOption & option) const Value(const QCommandLineOption & option) const SetSingleDashWordOptionMode(QCommandLineParser::SingleDashWordOptionMode singleDashWordOptionMode) SetOptionsAfterPositionalArgumentsMode(QCommandLineParser::OptionsAfterPositionalArgumentsMode parsingMode) SetApplicationDescription(const QString & description) IsSet(const QCommandLineOption & option) const AddOption(const QCommandLineOption & option)ĪddPositionalArgument(const QString & name, const QString & description, const QString & syntax = QString())
