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 <thiago.macieira@intel.com>
This commit is contained in:
Marc Mutz 2022-05-17 09:55:09 +02:00
parent 7b736e1faf
commit 042bab072a
3 changed files with 9 additions and 14 deletions

View File

@ -20,7 +20,7 @@
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
Q_AUTOTEST_EXPORT uint qGlobalPostedEventsCount(); Q_AUTOTEST_EXPORT qsizetype qGlobalPostedEventsCount();
class Q_CORE_EXPORT QAbstractEventDispatcherPrivate : public QObjectPrivate class Q_CORE_EXPORT QAbstractEventDispatcherPrivate : public QObjectPrivate
{ {

View File

@ -321,10 +321,10 @@ Q_CONSTINIT bool QCoreApplicationPrivate::is_app_running = false;
// app closing down if true // app closing down if true
Q_CONSTINIT bool QCoreApplicationPrivate::is_app_closing = false; Q_CONSTINIT bool QCoreApplicationPrivate::is_app_closing = false;
uint qGlobalPostedEventsCount() qsizetype qGlobalPostedEventsCount()
{ {
QThreadData *currentThreadData = QThreadData::current(); const QPostEventList &l = QThreadData::current()->postEventList;
return currentThreadData->postEventList.size() - currentThreadData->postEventList.startOffset; return l.size() - l.startOffset;
} }
Q_CONSTINIT QAbstractEventDispatcher *QCoreApplicationPrivate::eventDispatcher = nullptr; Q_CONSTINIT QAbstractEventDispatcher *QCoreApplicationPrivate::eventDispatcher = nullptr;

View File

@ -520,7 +520,7 @@ class GlobalPostedEventsCountObject : public QObject
Q_OBJECT Q_OBJECT
public: public:
QList<int> globalPostedEventsCount; QList<qsizetype> globalPostedEventsCount;
bool event(QEvent *event) override bool event(QEvent *event) override
{ {
@ -537,7 +537,7 @@ void tst_QCoreApplication::globalPostedEventsCount()
TestApplication app(argc, argv); TestApplication app(argc, argv);
QCoreApplication::sendPostedEvents(); QCoreApplication::sendPostedEvents();
QCOMPARE(qGlobalPostedEventsCount(), 0u); QCOMPARE(qGlobalPostedEventsCount(), qsizetype(0));
GlobalPostedEventsCountObject x; GlobalPostedEventsCountObject x;
QCoreApplication::postEvent(&x, new QEvent(QEvent::User)); 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)); 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(); QCoreApplication::sendPostedEvents();
QCOMPARE(qGlobalPostedEventsCount(), 0u); QCOMPARE(qGlobalPostedEventsCount(), qsizetype(0));
QList<int> expected = QList<int>() const QList<qsizetype> expected = {4, 3, 2, 1, 0};
<< 4
<< 3
<< 2
<< 1
<< 0;
QCOMPARE(x.globalPostedEventsCount, expected); QCOMPARE(x.globalPostedEventsCount, expected);
} }
#endif // QT_BUILD_INTERNAL #endif // QT_BUILD_INTERNAL