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>
bb10
Ahmad Samir 2023-08-13 00:17:05 +03:00
parent 641bccce2a
commit 5522e33128
2 changed files with 6 additions and 5 deletions

View File

@ -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

View File

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