summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAhmad Samir <a.samirh78@gmail.com>2023-08-13 00:17:05 +0300
committerAhmad Samir <a.samirh78@gmail.com>2023-10-08 17:55:01 +0300
commit5522e3312896cc8fb94fd83ffd2e8063693f97fe (patch)
tree3122bb9e205c3db5ac8d922f71379b861fb6417f
parent641bccce2a80b2a7268c3b8409bdc957b9a510b5 (diff)
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 <ch.ehrlicher@gmx.de>
-rw-r--r--src/widgets/CMakeLists.txt2
-rw-r--r--src/widgets/widgets/qmenubar.cpp9
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 <qmenubar.h>
#include <qstyle.h>
@@ -1289,7 +1287,12 @@ void QMenuBarPrivate::handleReparent()
QList<QPointer<QWidget>> newParents;
// Remove event filters on ex-parents, keep them on still-parents
// The parents are always ordered in the vector
- foreach (const QPointer<QWidget> &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<QWidget> &w : copy) {
if (w) {
if (newParent == w) {
newParents.append(w);