diff options
| -rw-r--r-- | src/corelib/tools/qcommandlineparser.cpp | 22 | ||||
| -rw-r--r-- | src/corelib/tools/qcommandlineparser.h | 1 |
2 files changed, 19 insertions, 4 deletions
diff --git a/src/corelib/tools/qcommandlineparser.cpp b/src/corelib/tools/qcommandlineparser.cpp index c860b4d155e..0f5d9a68277 100644 --- a/src/corelib/tools/qcommandlineparser.cpp +++ b/src/corelib/tools/qcommandlineparser.cpp @@ -423,10 +423,8 @@ void QCommandLineParser::process(const QStringList &arguments) ::exit(EXIT_FAILURE); } - if (d->builtinVersionOption && isSet(QStringLiteral("version"))) { - printf("%s %s\n", qPrintable(QCoreApplication::applicationName()), qPrintable(QCoreApplication::applicationVersion())); - ::exit(EXIT_SUCCESS); - } + if (d->builtinVersionOption && isSet(QStringLiteral("version"))) + showVersion(); if (d->builtinHelpOption && isSet(QStringLiteral("help"))) showHelp(EXIT_SUCCESS); @@ -816,6 +814,22 @@ QStringList QCommandLineParser::unknownOptionNames() const } /*! + Displays the version information from QCoreApplication::applicationVersion(), + 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). + + \sa addVersionOption() + \since 5.4 +*/ +Q_NORETURN void QCommandLineParser::showVersion() +{ + fprintf(stdout, "%s %s\n", qPrintable(QCoreApplication::applicationName()), qPrintable(QCoreApplication::applicationVersion())); + ::exit(EXIT_SUCCESS); +} + +/*! Displays the help information, and exits the application. This is automatically triggered by the --help option, but can also be used to display the help when the user is not invoking the diff --git a/src/corelib/tools/qcommandlineparser.h b/src/corelib/tools/qcommandlineparser.h index 5a7061f0313..946d4dd238b 100644 --- a/src/corelib/tools/qcommandlineparser.h +++ b/src/corelib/tools/qcommandlineparser.h @@ -92,6 +92,7 @@ public: QStringList optionNames() const; QStringList unknownOptionNames() const; + Q_NORETURN void showVersion(); Q_NORETURN void showHelp(int exitCode = 0); QString helpText() const; |
