From a887891271a52b2546265c13c6dc70fdd08507e3 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Tue, 17 May 2022 10:13:55 +0200 Subject: QCoreApplication: port some indexed to ranged for loops ... fixing the int/qsizetype mismatches in the old code. These loops trivially don't modify the container under iteration, so using a ranged for loop is safe. Pick-to: 6.3 6.2 Task-number: QTBUG-103532 Change-Id: I1c9e1bffceea0ada54007d313aebe2e688fa9122 Reviewed-by: Thiago Macieira --- src/corelib/kernel/qcoreapplication.cpp | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) (limited to 'src/corelib/kernel/qcoreapplication.cpp') diff --git a/src/corelib/kernel/qcoreapplication.cpp b/src/corelib/kernel/qcoreapplication.cpp index 0dafc40381..71e1b88cd8 100644 --- a/src/corelib/kernel/qcoreapplication.cpp +++ b/src/corelib/kernel/qcoreapplication.cpp @@ -289,8 +289,8 @@ static void qt_call_pre_routines() // the function to be executed every time QCoreApplication is created. list = *preRList; } - for (int i = 0; i < list.count(); ++i) - list.at(i)(); + for (QtCleanUpFunction f : std::as_const(list)) + f(); } void Q_CORE_EXPORT qt_call_post_routines() @@ -472,8 +472,7 @@ void QCoreApplicationPrivate::cleanupThreadData() // need to clear the state of the mainData, just in case a new QCoreApplication comes along. const auto locker = qt_scoped_lock(thisThreadData->postEventList.mutex); - for (int i = 0; i < thisThreadData->postEventList.size(); ++i) { - const QPostEvent &pe = thisThreadData->postEventList.at(i); + for (const QPostEvent &pe : std::as_const(thisThreadData->postEventList)) { if (pe.event) { --pe.receiver->d_func()->postedEvents; pe.event->m_posted = false; @@ -1607,8 +1606,7 @@ bool QCoreApplication::compressEvent(QEvent *event, QObject *receiver, QPostEven // compress posted timers to this object. if (event->type() == QEvent::Timer && receiver->d_func()->postedEvents > 0) { int timerId = ((QTimerEvent *) event)->timerId(); - for (int i=0; isize(); ++i) { - const QPostEvent &e = postedEvents->at(i); + for (const QPostEvent &e : std::as_const(*postedEvents)) { if (e.receiver == receiver && e.event && e.event->type() == QEvent::Timer && ((QTimerEvent *) e.event)->timerId() == timerId) { delete event; @@ -1631,8 +1629,7 @@ bool QCoreApplication::compressEvent(QEvent *event, QObject *receiver, QPostEven } if (event->type() == QEvent::Quit && receiver->d_func()->postedEvents > 0) { - for (int i = 0; i < postedEvents->size(); ++i) { - const QPostEvent &cur = postedEvents->at(i); + for (const QPostEvent &cur : std::as_const(*postedEvents)) { if (cur.receiver != receiver || cur.event == nullptr || cur.event->type() != event->type()) @@ -1916,8 +1913,7 @@ void QCoreApplicationPrivate::removePostedEvent(QEvent * event) #endif } - for (int i = 0; i < data->postEventList.size(); ++i) { - const QPostEvent & pe = data->postEventList.at(i); + for (const QPostEvent &pe : std::as_const(data->postEventList)) { if (pe.event == event) { #ifndef QT_NO_DEBUG qWarning("QCoreApplication::removePostedEvent: Event of type %d deleted while posted to %s %s", -- cgit v1.2.3