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)) {