From e48e2b3b4a65dadc0cc013bcc5132db8c530a3f3 Mon Sep 17 00:00:00 2001 From: Ahmad Samir Date: Mon, 14 Aug 2023 03:07:18 +0300 Subject: [PATCH] tst_Gestures: compile with QT_NO_FOREACH [1/2] GestureWidget::ignoredGestures QSet: - elements are inserted in the container in a top-level test function, then a CustomEvent is constructed and sendCustomGesture() is called, which sends the events, invoking the GestureWidget::event() overload, the latter iterates over the container, thus the container isn't changed while it's being iterated over, because the code can't recurse into the top-level test function and that's where the container is modified later on (by inserting or by calling widget.reset() which clears the container) - the loop body doesn't change the container So use ranged-for and std::as_const. The same logic applies to the GestureItem::ignoredGestures QSet. Task-number: QTBUG-115839 Change-Id: Icf95e90a8af5aa7e947035704121557494afc326 Reviewed-by: Volker Hilsheimer --- tests/auto/other/gestures/tst_gestures.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/auto/other/gestures/tst_gestures.cpp b/tests/auto/other/gestures/tst_gestures.cpp index 42a61955b6..be40887be6 100644 --- a/tests/auto/other/gestures/tst_gestures.cpp +++ b/tests/auto/other/gestures/tst_gestures.cpp @@ -210,7 +210,7 @@ protected: QGestureEvent *e = static_cast(event); ++gestureEventsReceived; eventsPtr = &events; - foreach(Qt::GestureType type, ignoredGestures) + for (Qt::GestureType type : std::as_const(ignoredGestures)) e->ignore(e->gesture(type)); } else if (event->type() == QEvent::GestureOverride) { ++gestureOverrideEventsReceived; @@ -744,7 +744,7 @@ public: ++gestureEventsReceived; eventsPtr = &events; QGestureEvent *e = static_cast(event); - foreach(Qt::GestureType type, ignoredGestures) + for (Qt::GestureType type : std::as_const(ignoredGestures)) e->ignore(e->gesture(type)); foreach(QGesture *g, e->gestures()) { switch (g->state()) {