Skip to main content

QCommandLineParser

Struct QCommandLineParser 

Source
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

Source

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.

Source

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.

Source

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.

Source

pub fn application_description(&self) -> QString

Returns the application description.

Source

pub fn clear_positional_arguments(&mut self)

Clears the definitions of additional arguments from the help text.

Source

pub fn error_text(&self) -> QString

Returns a translated error text for the user. This should only be called when parse returns false.

Source

pub fn help_text(&self) -> QString

Returns a string containing the complete help information.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn set_application_description(&mut self, description: &QString)

Sets the application description shown by help_text.

Source

pub fn set_single_dash_word_option_mode( &mut self, single_dash_word_option_mode: QCommandLineParserSingleDashWordOptionMode, )

Sets the parsing mode to single_dash_word_option_mode. This must be called before process or parse.

Source

pub fn set_options_after_positional_arguments_mode( &mut self, parsing_mode: QCommandLineParserOptionsAfterPositionalArgumentsMode, )

Sets the parsing mode to parsing_mode. This must be called before process or parse.

Source

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

Source

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

Source

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.

Source

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.

Source

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

Source§

fn clone(&self) -> QCommandLineParser

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for QCommandLineParser

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for QCommandLineParser

Source§

fn default() -> Self

Constructs a command line parser object.

Source§

impl Drop for QCommandLineParser

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl ExternType for QCommandLineParser

Source§

type Id = (Q, C, o, m, m, a, n, d, L, i, n, e, P, a, r, s, e, r)

A type-level representation of the type’s C++ namespace and type name. Read more
Source§

type Kind = Trivial

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.