The QCommandLineOption class defines a possible command-line option. 更多...
| 頭: | #include <QCommandLineOption> |
| qmake: | QT += core |
| Since: | Qt 5.2 |
| enum | Flag { HiddenFromHelp, ShortOptionStyle } |
| flags | Flags |
| QCommandLineOption (const QString & name ) | |
| QCommandLineOption (const QStringList & 名稱 ) | |
| QCommandLineOption (const QString & name , const QString & 描述 , const QString & valueName = QString(), const QString & defaultValue = QString()) | |
| QCommandLineOption (const QStringList & 名稱 , const QString & 描述 , const QString & valueName = QString(), const QString & defaultValue = QString()) | |
| QCommandLineOption (const QCommandLineOption & other ) | |
| ~QCommandLineOption () | |
| QStringList | defaultValues () const |
| QString | description () const |
| QCommandLineOption::Flags | flags () const |
| QStringList | 名稱 () const |
| void | setDefaultValue (const QString & defaultValue ) |
| void | setDefaultValues (const QStringList & defaultValues ) |
| void | setDescription (const QString & 描述 ) |
| void | setFlags (QCommandLineOption::Flags flags ) |
| void | setValueName (const QString & valueName ) |
| void | swap (QCommandLineOption & other ) |
| QString | valueName () const |
| QCommandLineOption & | operator= (const QCommandLineOption & other ) |
| QCommandLineOption & | operator= (QCommandLineOption && other ) |
The QCommandLineOption class defines a possible command-line option.
This class is used to describe an option on the command line. It allows different ways of defining the same option with multiple aliases possible. It is also used to describe how the option is used - it may be a flag (e.g.
-v
) or take a value (e.g.
-o file
).
範例:
QCommandLineOption verboseOption("verbose", "Verbose mode. Prints out more information."); QCommandLineOption outputOption(QStringList() << "o" << "output", "Write generated data into <file>.", "file");
另請參閱 QCommandLineParser .
| 常量 | 值 | 描述 |
|---|---|---|
QCommandLineOption::HiddenFromHelp
|
0x1
|
Hide this option in the user-visible help output. All options are visible by default. Setting this flag for a particular option makes it internal, i.e. not listed in the help output. |
QCommandLineOption::ShortOptionStyle
|
0x2
|
The option will always be understood as a short option, regardless of what was set by
QCommandLineParser::setSingleDashWordOptionMode
. This allows flags such as
-DDEFINE=VALUE
or
-I/include/path
to be interpreted as short flags even when the parser is in
QCommandLineParser::ParseAsLongOptions
模式。
|
Flags 類型是 typedef 對於 QFlags <Flag>。它存儲 Flag 值的 OR (或) 組閤。
另請參閱 QCommandLineOption::setFlags () 和 QCommandLineOption::flags ().
Constructs a command line option object with the name name .
The name can be either short or long. If the name is one character in length, it is considered a short name. Option names must not be empty, must not start with a dash or a slash character, must not contain a
=
and cannot be repeated.
另請參閱 setDescription (), setValueName (),和 setDefaultValues ().
Constructs a command line option object with the names 名稱 .
This overload allows to set multiple names for the option, for instance
o
and
output
.
The names can be either short or long. Any name in the list that is one character in length is a short name. Option names must not be empty, must not start with a dash or a slash character, must not contain a
=
and cannot be repeated.
另請參閱 setDescription (), setValueName (),和 setDefaultValues ().
Constructs a command line option object with the given arguments.
The name of the option is set to
name
. The name can be either short or long. If the name is one character in length, it is considered a short name. Option names must not be empty, must not start with a dash or a slash character, must not contain a
=
and cannot be repeated.
描述被設為 描述 . It is customary to add a "." at the end of the description.
此外, valueName needs to be set if the option expects a value. The default value for the option is set to defaultValue .
In Qt versions before 5.4, this constructor was
explicit
. In Qt 5.4 and later, it no longer is and can be used for C++11-style uniform initialization:
QCommandLineParser parser; parser.addOption({"verbose", "Verbose mode. Prints out more information."});
另請參閱 setDescription (), setValueName (),和 setDefaultValues ().
Constructs a command line option object with the given arguments.
This overload allows to set multiple names for the option, for instance
o
and
output
.
The names of the option are set to
名稱
. The names can be either short or long. Any name in the list that is one character in length is a short name. Option names must not be empty, must not start with a dash or a slash character, must not contain a
=
and cannot be repeated.
描述被設為 描述 . It is customary to add a "." at the end of the description.
此外, valueName needs to be set if the option expects a value. The default value for the option is set to defaultValue .
In Qt versions before 5.4, this constructor was
explicit
. In Qt 5.4 and later, it no longer is and can be used for C++11-style uniform initialization:
QCommandLineParser parser; parser.addOption({{"o", "output"}, "Write generated data into <file>.", "file"});
另請參閱 setDescription (), setValueName (),和 setDefaultValues ().
構造 QCommandLineOption object that is a copy of the QCommandLineOption 對象 other .
另請參閱 operator= ().
銷毀命令行選項對象。
返迴此選項的默認值設置。
另請參閱 setDefaultValues ().
返迴此選項的描述設置。
另請參閱 setDescription ().
Returns a set of flags that affect this command-line option.
該函數在 Qt 5.8 引入。
另請參閱 setFlags () 和 QCommandLineOption::Flags .
Returns the names set for this option.
Sets the default value used for this option to defaultValue .
The default value is used if the user of the application does not specify the option on the command line.
若 defaultValue is empty, the option has no default values.
另請參閱 defaultValues () 和 setDefaultValues ().
Sets the list of default values used for this option to defaultValues .
The default values are used if the user of the application does not specify the option on the command line.
另請參閱 defaultValues () 和 setDefaultValue ().
Sets the description used for this option to 描述 .
It is customary to add a "." at the end of the description.
The description is used by QCommandLineParser::showHelp ().
另請參閱 description ().
Set the set of flags that affect this command-line option to flags .
該函數在 Qt 5.8 引入。
另請參閱 flags () 和 QCommandLineOption::Flags .
Sets the name of the expected value, for the documentation, to valueName .
Options without a value assigned have a boolean-like behavior: either the user specifies --option or they don't.
Options with a value assigned need to set a name for the expected value, for the documentation of the option in the help output. An option with names
o
and
output
, and a value name of
file
will appear as
-o, --output <file>
.
調用 QCommandLineParser::value () if you expect the option to be present only once, and QCommandLineParser::values () if you expect that option to be present multiple times.
另請參閱 valueName ().
Swaps option other with this option. This operation is very fast and never fails.
返迴期望值的名稱。
若為空,選項不帶值。
另請參閱 setValueName ().
Makes a copy of the other object and assigns it to this QCommandLineOption 對象。
移動賦值 other 到此 QCommandLineOption 實例。
該函數在 Qt 5.2 引入。