diff options
| author | Kai Köhne <kai.koehne@qt.io> | 2023-05-24 09:20:45 +0200 |
|---|---|---|
| committer | Kai Köhne <kai.koehne@qt.io> | 2023-06-06 10:43:50 +0200 |
| commit | 1352dba3b05a5d9e8a59ccd86037d41bfcee6fb0 (patch) | |
| tree | 6738f26bf6d0fbf4cd8f6e23e04eb8d248b301f3 /src/corelib/tools/qcommandlineparser.cpp | |
| parent | 4d261c1b544330c5481b2ac2e42fbab764255ab5 (diff) | |
Doc: Small fixes to QCommandLineParser overview
Pick-to: 6.5 6.6
Change-Id: I535944b747ed511cfe5e6efe8ca2c13b52c2cfbb
Reviewed-by: Andreas Eliasson <andreas.eliasson@qt.io>
Diffstat (limited to 'src/corelib/tools/qcommandlineparser.cpp')
| -rw-r--r-- | src/corelib/tools/qcommandlineparser.cpp | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/src/corelib/tools/qcommandlineparser.cpp b/src/corelib/tools/qcommandlineparser.cpp index 0bab9dafe4a..633ae7562cc 100644 --- a/src/corelib/tools/qcommandlineparser.cpp +++ b/src/corelib/tools/qcommandlineparser.cpp @@ -125,24 +125,24 @@ QStringList QCommandLineParserPrivate::aliases(const QString &optionName) const The parser handles short names, long names, more than one name for the same option, and option values. - Options on the command line are recognized as starting with a single or - double \c{-} character(s). + Options on the command line are recognized as starting with one or two + \c{-} characters, followed by the option name. The option \c{-} (single dash alone) is a special case, often meaning standard - input, and not treated as an option. The parser will treat everything after the + input, and is not treated as an option. The parser will treat everything after the option \c{--} (double dash) as positional arguments. Short options are single letters. The option \c{v} would be specified by passing \c{-v} on the command line. In the default parsing mode, short options can be written in a compact form, for instance \c{-abc} is equivalent to \c{-a -b -c}. - The parsing mode for can be set to ParseAsLongOptions, in which case \c{-abc} + The parsing mode can be changed to ParseAsLongOptions, in which case \c{-abc} will be parsed as the long option \c{abc}. Long options are more than one letter long and cannot be compacted together. The long option \c{verbose} would be passed as \c{--verbose} or \c{-verbose}. - Passing values to options can be done using the assignment operator: \c{-v=value} - \c{--verbose=value}, or a space: \c{-v value} \c{--verbose value}, i.e. the next - argument is used as value (even if it starts with a \c{-}). + Passing values to options can be done by using the assignment operator (\c{-v=value}, + \c{--verbose=value}), or with a space (\c{-v value}, \c{--verbose value}). This + works even if the the value starts with a \c{-}. The parser does not support optional values - if an option is set to require a value, one must be present. If such an option is placed last @@ -157,13 +157,13 @@ QStringList QCommandLineParserPrivate::aliases(const QString &optionName) const Example: \snippet code/src_corelib_tools_qcommandlineparser_main.cpp 0 - If your compiler supports the C++11 standard, the three addOption() calls in - the above example can be simplified: + The three addOption() calls in the above example can be made more compact + by using addOptions(): \snippet code/src_corelib_tools_qcommandlineparser_main.cpp cxx11 Known limitation: the parsing of Qt options inside QCoreApplication and subclasses happens before QCommandLineParser exists, so it can't take it into account. This - means any option value that looks like a builtin Qt option, will be treated by + means any option value that looks like a builtin Qt option will be treated by QCoreApplication as a builtin Qt option. Example: \c{--profile -reverse} will lead to QGuiApplication seeing the -reverse option set, and removing it from QCoreApplication::arguments() before QCommandLineParser defines the \c{profile} |
