Change QCommandLineParser::showMessageAndExit() argument order

Looking at other similar Qt APIs, the type argument usually comes first.
The typical related examples can be QMessageBox() constructor taking
QIcon as a first parameter, and qFormatLogMessage() function, taking
message type as a first parameter.

This patch changes the order of arguments, so that MessageType enum
comes as a first argument.

Amends bad618606d64e943e3fa78e7d1dbc8e1fab55480.

Found in Qt 6.9 API review.

Change-Id: Ibbdef755a8676a2c556fe7f1c95009ad51320b98
Reviewed-by: David Faure <david.faure@kdab.com>
(cherry picked from commit 56114f4d1ed6ec26ff59a596caf09f5b4e0f5d68)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Ivan Solovev 2024-12-16 11:59:46 +01:00 committed by Qt Cherry-pick Bot
parent e69e53de8e
commit cc2213ab27
2 changed files with 11 additions and 8 deletions

View File

@ -562,7 +562,7 @@ static inline bool displayMessageBox()
\sa addVersionOption(), showHelp(), showVersion(), QCommandLineParser::MessageType \sa addVersionOption(), showHelp(), showVersion(), QCommandLineParser::MessageType
*/ */
Q_NORETURN void QCommandLineParser::showMessageAndExit(const QString &message, MessageType type, int exitCode) Q_NORETURN void QCommandLineParser::showMessageAndExit(MessageType type, const QString &message, int exitCode)
{ {
#if defined(Q_OS_WIN) && !defined(QT_BOOTSTRAPPED) #if defined(Q_OS_WIN) && !defined(QT_BOOTSTRAPPED)
if (displayMessageBox()) { if (displayMessageBox()) {
@ -601,8 +601,9 @@ Q_NORETURN void QCommandLineParser::showMessageAndExit(const QString &message, M
void QCommandLineParser::process(const QStringList &arguments) void QCommandLineParser::process(const QStringList &arguments)
{ {
if (!d->parse(arguments)) { if (!d->parse(arguments)) {
showMessageAndExit(QCoreApplication::applicationName() + ": "_L1 + errorText() + u'\n', showMessageAndExit(ErrorMessage,
ErrorMessage, EXIT_FAILURE); QCoreApplication::applicationName() + ": "_L1 + errorText() + u'\n',
EXIT_FAILURE);
} }
if (d->builtinVersionOption && isSet(QStringLiteral("version"))) if (d->builtinVersionOption && isSet(QStringLiteral("version")))
@ -1035,9 +1036,10 @@ QStringList QCommandLineParser::unknownOptionNames() const
*/ */
Q_NORETURN void QCommandLineParser::showVersion() Q_NORETURN void QCommandLineParser::showVersion()
{ {
showMessageAndExit(QCoreApplication::applicationName() + u' ' showMessageAndExit(InformationMessage,
QCoreApplication::applicationName() + u' '
+ QCoreApplication::applicationVersion() + u'\n', + QCoreApplication::applicationVersion() + u'\n',
InformationMessage, EXIT_SUCCESS); EXIT_SUCCESS);
} }
/*! /*!
@ -1058,8 +1060,9 @@ Q_NORETURN void QCommandLineParser::showHelp(int exitCode)
Q_NORETURN void QCommandLineParserPrivate::showHelp(int exitCode, bool includeQtOptions) Q_NORETURN void QCommandLineParserPrivate::showHelp(int exitCode, bool includeQtOptions)
{ {
QCommandLineParser::showMessageAndExit(helpText(includeQtOptions), QCommandLineParser::showMessageAndExit(QCommandLineParser::InformationMessage,
QCommandLineParser::InformationMessage, exitCode); helpText(includeQtOptions),
exitCode);
} }
/*! /*!

View File

@ -71,7 +71,7 @@ public:
InformationMessage, InformationMessage,
ErrorMessage, ErrorMessage,
}; };
Q_NORETURN static void showMessageAndExit(const QString &message, MessageType type, int exitCode = 0); Q_NORETURN static void showMessageAndExit(MessageType type, const QString &message, int exitCode = 0);
private: private:
Q_DISABLE_COPY(QCommandLineParser) Q_DISABLE_COPY(QCommandLineParser)