diff options
author | Yuhang Zhao <2546789017@qq.com> | 2023-04-21 19:23:29 +0800 |
---|---|---|
committer | Yuhang Zhao <yuhangzhao@deepin.org> | 2023-05-15 08:47:17 +0000 |
commit | b5d874e36fd39fa6e57ff27db27ae0b029949749 (patch) | |
tree | b81084d13361aa126bf20acf60430272a12dfeb5 /src/widgets | |
parent | 9a73bc5f3d48f6ccaef02871ad62284dd61eff38 (diff) | |
download | qtbase-b5d874e36fd39fa6e57ff27db27ae0b029949749.tar.gz |
Fix the QT_REQUIRE_VERSION macro
Rewrite the whole macro as a function and use QVersionNumber instead
of manual parsing to make it more modern and more readable.
Change-Id: I25498320ef6cd9f19be9267421e2727cd28cfd7c
Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Diffstat (limited to 'src/widgets')
-rw-r--r-- | src/widgets/dialogs/qmessagebox.h | 38 |
1 files changed, 23 insertions, 15 deletions
diff --git a/src/widgets/dialogs/qmessagebox.h b/src/widgets/dialogs/qmessagebox.h index 72f0840e80..161719e180 100644 --- a/src/widgets/dialogs/qmessagebox.h +++ b/src/widgets/dialogs/qmessagebox.h @@ -5,9 +5,13 @@ #define QMESSAGEBOX_H #include <QtWidgets/qtwidgetsglobal.h> - +#include <QtWidgets/qapplication.h> #include <QtWidgets/qdialog.h> +#include <QtCore/qanystringview.h> +#include <QtCore/qdebug.h> +#include <QtCore/qversionnumber.h> + QT_REQUIRE_CONFIG(messagebox); QT_BEGIN_NAMESPACE @@ -312,20 +316,24 @@ private: Q_DECLARE_OPERATORS_FOR_FLAGS(QMessageBox::StandardButtons) -#define QT_REQUIRE_VERSION(argc, argv, str) { QString s = QString::fromLatin1(str);\ -QString sq = QString::fromLatin1(qVersion()); \ -if ((sq.section(QChar::fromLatin1('.'),0,0).toInt()<<16)+\ -(sq.section(QChar::fromLatin1('.'),1,1).toInt()<<8)+\ -sq.section(QChar::fromLatin1('.'),2,2).toInt()<(s.section(QChar::fromLatin1('.'),0,0).toInt()<<16)+\ -(s.section(QChar::fromLatin1('.'),1,1).toInt()<<8)+\ -s.section(QChar::fromLatin1('.'),2,2).toInt()) { \ -if (!qApp){ \ - new QApplication(argc,argv); \ -} \ -QString s = QApplication::tr("Executable '%1' requires Qt "\ - "%2, found Qt %3.").arg(qAppName()).arg(QString::fromLatin1(\ -str)).arg(QString::fromLatin1(qVersion())); QMessageBox::critical(0, QApplication::tr(\ -"Incompatible Qt Library Error"), s, QMessageBox::Abort, 0); qFatal("%s", s.toLatin1().data()); }} +[[maybe_unused]] +static inline void qRequireVersion(int argc, char *argv[], QAnyStringView req) +{ + const auto required = QVersionNumber::fromString(req).normalized(); + const auto current = QVersionNumber::fromString(qVersion()).normalized(); + if (current >= required) + return; + std::unique_ptr<QApplication> application; + if (!qApp) + application = std::make_unique<QApplication>(argc, argv); + const QString message = QApplication::tr("Application \"%1\" requires Qt %2, found Qt %3.") + .arg(qAppName(), required.toString(), current.toString()); + QMessageBox::critical(nullptr, QApplication::tr("Incompatible Qt Library Error"), + message, QMessageBox::Abort); + qFatal().noquote() << message; +} + +#define QT_REQUIRE_VERSION(argc, argv, str) qRequireVersion(argc, argv, str); QT_END_NAMESPACE |