From 5522e3312896cc8fb94fd83ffd2e8063693f97fe Mon Sep 17 00:00:00 2001 From: Ahmad Samir Date: Sun, 13 Aug 2023 00:17:05 +0300 Subject: [PATCH] QMenuBar: compile with QT_NO_FOREACH The loop doesn't change the member container while iterating over it, but handleReparent() is called from eventFilter() and changeEvent(), so take a copy to iterate over. Task-number: QTBUG-115803 Change-Id: I58ff5bddf99f07a46348b7802432e0899b3170df Reviewed-by: Christian Ehrlicher --- src/widgets/CMakeLists.txt | 2 -- src/widgets/widgets/qmenubar.cpp | 9 ++++++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/widgets/CMakeLists.txt b/src/widgets/CMakeLists.txt index fc5a04634a..e7bd11578c 100644 --- a/src/widgets/CMakeLists.txt +++ b/src/widgets/CMakeLists.txt @@ -486,8 +486,6 @@ qt_internal_extend_target(Widgets CONDITION QT_FEATURE_menu qt_internal_extend_target(Widgets CONDITION QT_FEATURE_menubar SOURCES widgets/qmenubar.cpp widgets/qmenubar.h widgets/qmenubar_p.h - NO_PCH_SOURCES - widgets/qmenubar.cpp # undef QT_NO_FOREACH ) qt_internal_extend_target(Widgets CONDITION QT_FEATURE_progressbar diff --git a/src/widgets/widgets/qmenubar.cpp b/src/widgets/widgets/qmenubar.cpp index 4487e2be30..1a23ec5718 100644 --- a/src/widgets/widgets/qmenubar.cpp +++ b/src/widgets/widgets/qmenubar.cpp @@ -1,8 +1,6 @@ // Copyright (C) 2016 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only -#undef QT_NO_FOREACH // this file contains unported legacy Q_FOREACH uses - #include #include @@ -1289,7 +1287,12 @@ void QMenuBarPrivate::handleReparent() QList> newParents; // Remove event filters on ex-parents, keep them on still-parents // The parents are always ordered in the vector - foreach (const QPointer &w, oldParents) { + // + // Take a copy because this method is called from changeEvent() and eventFilter(), + // which might cause recursion into the class due to event processing, which might + // modify oldParents. + const auto copy = oldParents; + for (const QPointer &w : copy) { if (w) { if (newParent == w) { newParents.append(w);