Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
QCommandLineOption Class Reference

The QCommandLineOption class defines a possible command-line option. \inmodule QtCore. More...

#include <qcommandlineoption.h>

+ Collaboration diagram for QCommandLineOption:

Public Types

enum  Flag { HiddenFromHelp = 0x1 , ShortOptionStyle = 0x2 }
 \value HiddenFromHelp Hide this option in the user-visible help output. More...
 

Public Member Functions

 QCommandLineOption (const QString &name)
 Constructs a command line option object with the name name.
 
 QCommandLineOption (const QStringList &names)
 Constructs a command line option object with the names names.
 
 QCommandLineOption (const QString &name, const QString &description, const QString &valueName=QString(), const QString &defaultValue=QString())
 Constructs a command line option object with the given arguments.
 
 QCommandLineOption (const QStringList &names, const QString &description, const QString &valueName=QString(), const QString &defaultValue=QString())
 Constructs a command line option object with the given arguments.
 
 QCommandLineOption (const QCommandLineOption &other)
 Constructs a QCommandLineOption object that is a copy of the QCommandLineOption object other.
 
 ~QCommandLineOption ()
 Destroys the command line option object.
 
QCommandLineOptionoperator= (const QCommandLineOption &other)
 Move-assigns other to this QCommandLineOption instance.
 
void swap (QCommandLineOption &other) noexcept
 Swaps option other with this option.
 
QStringList names () const
 Returns the names set for this option.
 
void setValueName (const QString &name)
 Sets the name of the expected value, for the documentation, to valueName.
 
QString valueName () const
 Returns the name of the expected value.
 
void setDescription (const QString &description)
 Sets the description used for this option to description.
 
QString description () const
 Returns the description set for this option.
 
void setDefaultValue (const QString &defaultValue)
 Sets the default value used for this option to defaultValue.
 
void setDefaultValues (const QStringList &defaultValues)
 Sets the list of default values used for this option to defaultValues.
 
QStringList defaultValues () const
 Returns the default values set for this option.
 
Flags flags () const
 Returns a set of flags that affect this command-line option.
 
void setFlags (Flags aflags)
 Set the set of flags that affect this command-line option to flags.
 

Detailed Description

The QCommandLineOption class defines a possible command-line option. \inmodule QtCore.

Since
5.2

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}).

Examples:

QCommandLineOption verboseOption("verbose", "Verbose mode. Prints out more information.");
QCommandLineOption outputOption(QStringList() << "o" << "output", "Write generated data into <file>.", "file");
See also
QCommandLineParser

Definition at line 17 of file qcommandlineoption.h.

Member Enumeration Documentation

◆ Flag

\value HiddenFromHelp 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.

\value ShortOptionStyle 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 mode.

See also
QCommandLineOption::setFlags(), QCommandLineOption::flags()
Enumerator
HiddenFromHelp 
ShortOptionStyle 

Definition at line 20 of file qcommandlineoption.h.

Constructor & Destructor Documentation

◆ QCommandLineOption() [1/5]

QCommandLineOption::QCommandLineOption ( const QString & name)
explicit

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.

See also
setDescription(), setValueName(), setDefaultValues()

Definition at line 80 of file qcommandlineoption.cpp.

◆ QCommandLineOption() [2/5]

QCommandLineOption::QCommandLineOption ( const QStringList & names)
explicit

Constructs a command line option object with the names 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.

See also
setDescription(), setValueName(), setDefaultValues()

Definition at line 98 of file qcommandlineoption.cpp.

◆ QCommandLineOption() [3/5]

QCommandLineOption::QCommandLineOption ( const QString & name,
const QString & description,
const QString & valueName = QString(),
const QString & defaultValue = QString() )

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.

The description is set to description. It is customary to add a "." at the end of the description.

In addition, the 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 uniform initialization:

parser.addOption({"verbose", "Verbose mode. Prints out more information."});
See also
setDescription(), setValueName(), setDefaultValues()

Definition at line 125 of file qcommandlineoption.cpp.

References description(), setDefaultValue(), setDescription(), setValueName(), and valueName().

+ Here is the call graph for this function:

◆ QCommandLineOption() [4/5]

QCommandLineOption::QCommandLineOption ( const QStringList & names,
const QString & description,
const QString & valueName = QString(),
const QString & defaultValue = QString() )

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 names. 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.

The description is set to description. It is customary to add a "." at the end of the description.

In addition, the 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 uniform initialization:

parser.addOption({{"o", "output"}, "Write generated data into <file>.", "file"});
See also
setDescription(), setValueName(), setDefaultValues()

Definition at line 160 of file qcommandlineoption.cpp.

References description(), setDefaultValue(), setDescription(), setValueName(), and valueName().

+ Here is the call graph for this function:

◆ QCommandLineOption() [5/5]

QCommandLineOption::QCommandLineOption ( const QCommandLineOption & other)

Constructs a QCommandLineOption object that is a copy of the QCommandLineOption object other.

See also
operator=()

Definition at line 176 of file qcommandlineoption.cpp.

◆ ~QCommandLineOption()

QCommandLineOption::~QCommandLineOption ( )

Destroys the command line option object.

Definition at line 184 of file qcommandlineoption.cpp.

Member Function Documentation

◆ defaultValues()

QStringList QCommandLineOption::defaultValues ( ) const

Returns the default values set for this option.

See also
setDefaultValues()

Definition at line 351 of file qcommandlineoption.cpp.

References QCommandLineOptionPrivate::defaultValues.

Referenced by setDefaultValues().

+ Here is the caller graph for this function:

◆ description()

QString QCommandLineOption::description ( ) const

Returns the description set for this option.

See also
setDescription()

Definition at line 307 of file qcommandlineoption.cpp.

References QCommandLineOptionPrivate::description.

Referenced by QCommandLineOption(), QCommandLineOption(), and setDescription().

+ Here is the caller graph for this function:

◆ flags()

QCommandLineOption::Flags QCommandLineOption::flags ( ) const

Returns a set of flags that affect this command-line option.

Since
5.8
See also
setFlags(), QCommandLineOption::Flags

Definition at line 362 of file qcommandlineoption.cpp.

References QCommandLineOptionPrivate::flags.

Referenced by setFlags().

+ Here is the caller graph for this function:

◆ names()

QStringList QCommandLineOption::names ( ) const

Returns the names set for this option.

Definition at line 208 of file qcommandlineoption.cpp.

References QCommandLineOptionPrivate::names.

Referenced by QCommandLineParserPrivate::aliases().

+ Here is the caller graph for this function:

◆ operator=()

QCommandLineOption & QCommandLineOption::operator= ( const QCommandLineOption & other)

Move-assigns other to this QCommandLineOption instance.

Makes a copy of the other object and assigns it to this QCommandLineOption object.

Since
5.2

Definition at line 192 of file qcommandlineoption.cpp.

References other().

+ Here is the call graph for this function:

◆ setDefaultValue()

void QCommandLineOption::setDefaultValue ( const QString & defaultValue)

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.

If defaultValue is empty, the option has no default values.

See also
defaultValues() setDefaultValues()

Definition at line 322 of file qcommandlineoption.cpp.

References QCommandLineOptionPrivate::defaultValues, and QString::isEmpty().

Referenced by QCommandLineOption(), and QCommandLineOption().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setDefaultValues()

void QCommandLineOption::setDefaultValues ( const QStringList & defaultValues)

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.

See also
defaultValues() setDefaultValue()

Definition at line 341 of file qcommandlineoption.cpp.

References QCommandLineOptionPrivate::defaultValues, and defaultValues().

+ Here is the call graph for this function:

◆ setDescription()

void QCommandLineOption::setDescription ( const QString & description)

Sets the description used for this option to description.

It is customary to add a "." at the end of the description.

The description is used by QCommandLineParser::showHelp().

See also
description()

Definition at line 297 of file qcommandlineoption.cpp.

References QCommandLineOptionPrivate::description, and description().

Referenced by QCommandLineOption(), QCommandLineOption(), runRcc(), and runUic().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setFlags()

void QCommandLineOption::setFlags ( Flags flags)

Set the set of flags that affect this command-line option to flags.

Since
5.8
See also
flags(), QCommandLineOption::Flags

Definition at line 373 of file qcommandlineoption.cpp.

References QCommandLineOptionPrivate::flags, and flags().

+ Here is the call graph for this function:

◆ setValueName()

void QCommandLineOption::setValueName ( const QString & valueName)

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>}.

Call 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.

See also
valueName()

Definition at line 271 of file qcommandlineoption.cpp.

References QCommandLineOptionPrivate::valueName, and valueName().

Referenced by QCommandLineOption(), and QCommandLineOption().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ swap()

void QCommandLineOption::swap ( QCommandLineOption & other)
inlinenoexcept

Swaps option other with this option.

This operation is very fast and never fails.

Definition at line 41 of file qcommandlineoption.h.

References d, and other().

+ Here is the call graph for this function:

◆ valueName()

QString QCommandLineOption::valueName ( ) const

Returns the name of the expected value.

If empty, the option doesn't take a value.

See also
setValueName()

Definition at line 283 of file qcommandlineoption.cpp.

References QCommandLineOptionPrivate::valueName.

Referenced by QCommandLineOption(), QCommandLineOption(), QCommandLineParserPrivate::parse(), QCommandLineParserPrivate::parseOptionValue(), and setValueName().

+ Here is the caller graph for this function:

The documentation for this class was generated from the following files: