pub struct QCommandLineParser { /* private fields */ }Expand description
The QCommandLineParser class provides a means for handling the command line options.
Qt Documentation: QCommandLineParser
Implementations§
Source§impl QCommandLineParser
impl QCommandLineParser
Sourcepub fn add_help_option(&mut self) -> QCommandLineOption
pub fn add_help_option(&mut self) -> QCommandLineOption
Adds help options to the command-line parser.
The options specified for this command-line are described by -h or --help. On Windows, the alternative -? is also supported. The option --help-all extends that to include generic Qt options, not defined by this command, in the output.
These options are handled automatically by QCommandLineParser.
Sourcepub fn add_option(&mut self, option: &QCommandLineOption) -> bool
pub fn add_option(&mut self, option: &QCommandLineOption) -> bool
Adds the option option to look for while parsing.
Returns true if adding the option was successful; otherwise returns false.
Adding the option fails if there is no name attached to the option, or the option has a name that clashes with an option name added before.
Sourcepub fn add_version_option(&mut self) -> QCommandLineOption
pub fn add_version_option(&mut self) -> QCommandLineOption
Adds the -v / --version option, which displays the version string of the application.
This option is handled automatically by QCommandLineParser.
Sourcepub fn application_description(&self) -> QString
pub fn application_description(&self) -> QString
Returns the application description.
Sourcepub fn clear_positional_arguments(&mut self)
pub fn clear_positional_arguments(&mut self)
Clears the definitions of additional arguments from the help text.
Sourcepub fn error_text(&self) -> QString
pub fn error_text(&self) -> QString
Returns a translated error text for the user. This should only be called when parse returns false.
Sourcepub fn option_names(&self) -> QStringList
pub fn option_names(&self) -> QStringList
Returns a list of option names that were found.
This returns a list of all the recognized option names found by the parser, in the order in which they were found. For any long options that were in the form {–option=value}, the value part will have been dropped.
The names in this list do not include the preceding dash characters. Names may appear more than once in this list if they were encountered more than once by the parser.
Any entry in the list can be used with value or with values to get any relevant option values.
Sourcepub fn parse(&mut self, arguments: &QStringList) -> bool
pub fn parse(&mut self, arguments: &QStringList) -> bool
Parses the command line arguments.
Most programs don’t need to call this, a simple call to process is enough.
This function is more low-level, and only does the parsing. The application will have to take care of the error handling, using error_text if this function returns false. This can be useful for instance to show a graphical error message in graphical programs.
Calling this function instead of process can also be useful in order to ignore unknown options temporarily, because more option definitions will be provided later on (depending on one of the arguments), before calling process.
Don’t forget that arguments must start with the name of the executable (ignored, though).
Returns false in case of a parse error (unknown option or missing value); returns true otherwise.
Sourcepub fn positional_arguments(&self) -> QStringList
pub fn positional_arguments(&self) -> QStringList
Returns a list of positional arguments.
These are all of the arguments that were not recognized as part of an option.
Sourcepub fn process(&mut self, arguments: &QStringList)
pub fn process(&mut self, arguments: &QStringList)
Processes the command line arguments.
In addition to parsing the options (like parse), this function also handles the builtin options and handles errors.
The builtin options are --version if add_version_option was called and --help / --help-all if add_help_option was called.
When invoking one of these options, or when an error happens (for instance an unknown option was passed), the current process will then stop, using the exit() function.
Sourcepub fn set_application_description(&mut self, description: &QString)
pub fn set_application_description(&mut self, description: &QString)
Sets the application description shown by help_text.
Sourcepub fn set_single_dash_word_option_mode(
&mut self,
single_dash_word_option_mode: QCommandLineParserSingleDashWordOptionMode,
)
pub fn set_single_dash_word_option_mode( &mut self, single_dash_word_option_mode: QCommandLineParserSingleDashWordOptionMode, )
Sourcepub fn set_options_after_positional_arguments_mode(
&mut self,
parsing_mode: QCommandLineParserOptionsAfterPositionalArgumentsMode,
)
pub fn set_options_after_positional_arguments_mode( &mut self, parsing_mode: QCommandLineParserOptionsAfterPositionalArgumentsMode, )
Sourcepub fn show_version(&mut self)
pub fn show_version(&mut self)
Displays the version information from QCoreApplication::application_version, and exits the application.
This is automatically triggered by the –version option, but can also be used to display the version when not using process. The exit code is set to EXIT_SUCCESS (0).
Sourcepub fn unknown_option_names(&self) -> QStringList
pub fn unknown_option_names(&self) -> QStringList
Returns a list of unknown option names.
This list will include both long and short name options that were not recognized. For any long options that were in the form {–option=value}, the value part will have been dropped and only the long name is added.
The names in this list do not include the preceding dash characters. Names may appear more than once in this list if they were encountered more than once by the parser.
Source§impl QCommandLineParser
impl QCommandLineParser
Sourcepub fn value(&self, option_name: &QString) -> QString
pub fn value(&self, option_name: &QString) -> QString
Returns the option value found for the given option name option_name, or an empty string if not found.
The name provided can be any long or short name of any option that was added with add_option. All the option names are treated as being equivalent. If the name is not recognized or that option was not present, an empty string is returned.
For options found by the parser, the last value found for that option is returned. If the option wasn’t specified on the command line, the default value is returned.
If the option does not take a value, a warning is printed, and an empty string is returned.
Sourcepub fn values(&self, option_name: &QString) -> QStringList
pub fn values(&self, option_name: &QString) -> QStringList
Returns a list of option values found for the given option name option_name, or an empty list if not found.
The name provided can be any long or short name of any option that was added with add_option. All the options names are treated as being equivalent. If the name is not recognized or that option was not present, an empty list is returned.
For options found by the parser, the list will contain an entry for each time the option was encountered by the parser. If the option wasn’t specified on the command line, the default values are returned.
An empty list is returned if the option does not take a value.
Sourcepub fn is_set(&self, name: &QString) -> bool
pub fn is_set(&self, name: &QString) -> bool
Checks whether the option name was passed to the application.
Returns true if the option name was set, false otherwise.
The name provided can be any long or short name of any option that was added with add_option. All the options names are treated as being equivalent. If the name is not recognized or that option was not present, false is returned.
Trait Implementations§
Source§impl Clone for QCommandLineParser
impl Clone for QCommandLineParser
Source§fn clone(&self) -> QCommandLineParser
fn clone(&self) -> QCommandLineParser
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more