From c013c57c84270210c8bdfef2562aa67a857b3758 Mon Sep 17 00:00:00 2001 From: Ahmad Samir Date: Wed, 9 Aug 2023 16:38:55 +0300 Subject: [PATCH] QMdiArea: port Q_FOREACH to ranged-for, d->pendingPlacements Task-number: QTBUG-115803 Change-Id: Ibf2f049aacad925fea318c0ec490749e68e05b1d Reviewed-by: Richard Moe Gustavsen (cherry picked from commit 446af298b0c00a419ff8e373e6b2917fd2af44eb) Reviewed-by: Qt Cherry-pick Bot --- src/widgets/widgets/qmdiarea.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/widgets/widgets/qmdiarea.cpp b/src/widgets/widgets/qmdiarea.cpp index fdb3e6a1074..93de95547e7 100644 --- a/src/widgets/widgets/qmdiarea.cpp +++ b/src/widgets/widgets/qmdiarea.cpp @@ -2343,7 +2343,12 @@ void QMdiArea::showEvent(QShowEvent *showEvent) } if (!d->pendingPlacements.isEmpty()) { - foreach (QMdiSubWindow *window, d->pendingPlacements) { + // Nothing obvious in the loop body changes the container (in this code path) + // during iteration, this is calling into a non-const method that does change + // the container when called from other places. So take a copy anyway for good + // measure. + const auto copy = d->pendingPlacements; + for (QMdiSubWindow *window : copy) { if (!window) continue; if (!window->testAttribute(Qt::WA_Resized)) {