4#ifndef QCOMMANDLINEPARSER_H
5#define QCOMMANDLINEPARSER_H
7#include <QtCore/qstringlist.h>
9#include <QtCore/qcoreapplication.h>
10#include <QtCore/qcommandlineoption.h>
16class QCommandLineParserPrivate;
17class QCoreApplication;
21 Q_DECLARE_TR_FUNCTIONS(QCommandLineParser)
24 ~QCommandLineParser();
38 bool addOption(
const QCommandLineOption &commandLineOption);
39 bool addOptions(
const QList<QCommandLineOption> &options);
45 void addPositionalArgument(
const QString &name,
const QString &description,
const QString &syntax = QString());
48 void process(
const QStringList &arguments);
49 void process(
const QCoreApplication &app);
51 bool parse(
const QStringList &arguments);
54 bool isSet(
const QString &name)
const;
58 bool isSet(
const QCommandLineOption &option)
const;
77 Q_DISABLE_COPY(QCommandLineParser)
79 QCommandLineParserPrivate *
const d;
int main(int argc, char *argv[])
[2]
The QCommandLineParser class provides a means for handling the command line options.
QString value(const QString &name) const
Returns the option value found for the given option name optionName, or an empty string if not found.
bool parse(const QStringList &arguments)
Parses the command line arguments.
void addPositionalArgument(const QString &name, const QString &description, const QString &syntax=QString())
Defines an additional argument to the application, for the benefit of the help text.
QString applicationDescription() const
Returns the application description set in setApplicationDescription().
QStringList positionalArguments() const
Returns a list of positional arguments.
QStringList unknownOptionNames() const
Returns a list of unknown option names.
void process(const QCoreApplication &app)
This is an overloaded member function, provided for convenience. It differs from the above function o...
void setSingleDashWordOptionMode(SingleDashWordOptionMode parsingMode)
Sets the parsing mode to singleDashWordOptionMode.
Q_NORETURN void showVersion()
Displays the version information from QCoreApplication::applicationVersion(), and exits the applicati...
QStringList values(const QString &name) const
Returns a list of option values found for the given option name optionName, or an empty list if not f...
void setApplicationDescription(const QString &description)
Sets the application description shown by helpText().
bool addOptions(const QList< QCommandLineOption > &options)
bool addOption(const QCommandLineOption &commandLineOption)
Adds the option option to look for while parsing.
Q_NORETURN void showHelp(int exitCode=0)
Displays the help information, and exits the application.
QString errorText() const
Returns a translated error text for the user.
SingleDashWordOptionMode
This enum describes the way the parser interprets command-line options that use a single dash followe...
@ ParseAsCompactedShortOptions
bool isSet(const QString &name) const
Checks whether the option name was passed to the application.
static void showMessageAndExit(MessageType type, const QString &message, int exitCode=0)
QString helpText() const
Returns a string containing the complete help information.
QStringList optionNames() const
Returns a list of option names that were found.
void process(const QStringList &arguments)
Processes the command line arguments.
void clearPositionalArguments()
Clears the definitions of additional arguments from the help text.
OptionsAfterPositionalArgumentsMode
This enum describes the way the parser interprets options that occur after positional arguments.
@ ParseAsPositionalArguments
void setOptionsAfterPositionalArgumentsMode(OptionsAfterPositionalArgumentsMode mode)
Sets the parsing mode to parsingMode.
QCommandLineOption addVersionOption()
Adds the {-v} / {–version} option, which displays the version string of the application.
QCommandLineOption addHelpOption()
Adds help options to the command-line parser.
QT_REQUIRE_CONFIG(commandlineparser)