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 <volker.hilsheimer@qt.io>
bb10
Ahmad Samir 2023-08-14 03:07:18 +03:00
parent 29af4b1833
commit e48e2b3b4a
1 changed files with 2 additions and 2 deletions

View File

@ -210,7 +210,7 @@ protected:
QGestureEvent *e = static_cast<QGestureEvent*>(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<QGestureEvent *>(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()) {