From 042bab072a65f2f3054531ec4f7eb28afbe38e78 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Tue, 17 May 2022 09:55:09 +0200 Subject: [PATCH] Fix return value of qGlobalPostedEventsCount() The unsigned return value was very un-Qt-ish, and, indeed, tst_QCoreApplication just stored the result in ints. Port to qsizetype, being the type of the expression that the function calculates. Task-number: QTBUG-103532 Change-Id: I95a81a686439b0686faad7a430adeaab66dc9e8d Reviewed-by: Thiago Macieira --- src/corelib/kernel/qabstracteventdispatcher_p.h | 2 +- src/corelib/kernel/qcoreapplication.cpp | 6 +++--- .../qcoreapplication/tst_qcoreapplication.cpp | 15 +++++---------- 3 files changed, 9 insertions(+), 14 deletions(-) diff --git a/src/corelib/kernel/qabstracteventdispatcher_p.h b/src/corelib/kernel/qabstracteventdispatcher_p.h index 81ce39ffb80..e7b1ac3b24f 100644 --- a/src/corelib/kernel/qabstracteventdispatcher_p.h +++ b/src/corelib/kernel/qabstracteventdispatcher_p.h @@ -20,7 +20,7 @@ QT_BEGIN_NAMESPACE -Q_AUTOTEST_EXPORT uint qGlobalPostedEventsCount(); +Q_AUTOTEST_EXPORT qsizetype qGlobalPostedEventsCount(); class Q_CORE_EXPORT QAbstractEventDispatcherPrivate : public QObjectPrivate { diff --git a/src/corelib/kernel/qcoreapplication.cpp b/src/corelib/kernel/qcoreapplication.cpp index 1e8b209ff8c..0dafc403810 100644 --- a/src/corelib/kernel/qcoreapplication.cpp +++ b/src/corelib/kernel/qcoreapplication.cpp @@ -321,10 +321,10 @@ Q_CONSTINIT bool QCoreApplicationPrivate::is_app_running = false; // app closing down if true Q_CONSTINIT bool QCoreApplicationPrivate::is_app_closing = false; -uint qGlobalPostedEventsCount() +qsizetype qGlobalPostedEventsCount() { - QThreadData *currentThreadData = QThreadData::current(); - return currentThreadData->postEventList.size() - currentThreadData->postEventList.startOffset; + const QPostEventList &l = QThreadData::current()->postEventList; + return l.size() - l.startOffset; } Q_CONSTINIT QAbstractEventDispatcher *QCoreApplicationPrivate::eventDispatcher = nullptr; diff --git a/tests/auto/corelib/kernel/qcoreapplication/tst_qcoreapplication.cpp b/tests/auto/corelib/kernel/qcoreapplication/tst_qcoreapplication.cpp index 93d81980904..8ddca93cb73 100644 --- a/tests/auto/corelib/kernel/qcoreapplication/tst_qcoreapplication.cpp +++ b/tests/auto/corelib/kernel/qcoreapplication/tst_qcoreapplication.cpp @@ -520,7 +520,7 @@ class GlobalPostedEventsCountObject : public QObject Q_OBJECT public: - QList globalPostedEventsCount; + QList globalPostedEventsCount; bool event(QEvent *event) override { @@ -537,7 +537,7 @@ void tst_QCoreApplication::globalPostedEventsCount() TestApplication app(argc, argv); QCoreApplication::sendPostedEvents(); - QCOMPARE(qGlobalPostedEventsCount(), 0u); + QCOMPARE(qGlobalPostedEventsCount(), qsizetype(0)); GlobalPostedEventsCountObject x; QCoreApplication::postEvent(&x, new QEvent(QEvent::User)); @@ -545,17 +545,12 @@ void tst_QCoreApplication::globalPostedEventsCount() QCoreApplication::postEvent(&x, new QEvent(QEvent::User)); QCoreApplication::postEvent(&x, new QEvent(QEvent::User)); QCoreApplication::postEvent(&x, new QEvent(QEvent::User)); - QCOMPARE(qGlobalPostedEventsCount(), 5u); + QCOMPARE(qGlobalPostedEventsCount(), qsizetype(5)); QCoreApplication::sendPostedEvents(); - QCOMPARE(qGlobalPostedEventsCount(), 0u); + QCOMPARE(qGlobalPostedEventsCount(), qsizetype(0)); - QList expected = QList() - << 4 - << 3 - << 2 - << 1 - << 0; + const QList expected = {4, 3, 2, 1, 0}; QCOMPARE(x.globalPostedEventsCount, expected); } #endif // QT_BUILD_INTERNAL