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