From 6b7c354f5af65f263dc8526f1e2362aeb0eedfeb Mon Sep 17 00:00:00 2001 From: Ahmad Samir Date: Mon, 14 Aug 2023 16:32:28 +0300 Subject: [PATCH] tst_QKeyEvent: compile with QT_NO_FOREACH The containers are local (window.keyEvents is a member of Window, which is constructed on the stack, so a local container too), and they are not changed during iteration, so use ranged-for and std::as_const. Drive-by change: make loop variable a const&. Task-number: QTBUG-115839 Change-Id: I9ad40068ff6209cf57f31ce0d4f38882eddbfc44 Reviewed-by: Marc Mutz --- tests/auto/gui/kernel/qkeyevent/tst_qkeyevent.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/tests/auto/gui/kernel/qkeyevent/tst_qkeyevent.cpp b/tests/auto/gui/kernel/qkeyevent/tst_qkeyevent.cpp index 7d8e0aa5dc6..9fbf14bbec4 100644 --- a/tests/auto/gui/kernel/qkeyevent/tst_qkeyevent.cpp +++ b/tests/auto/gui/kernel/qkeyevent/tst_qkeyevent.cpp @@ -1,8 +1,6 @@ // Copyright (C) 2017 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only -#undef QT_NO_FOREACH // this file contains unported legacy Q_FOREACH uses - #include #include @@ -69,7 +67,7 @@ void tst_QKeyEvent::basicEventDelivery() QCOMPARE(window.keyEvents.size(), 2); QCOMPARE(window.keyEvents.first()->type(), QKeyEvent::KeyPress); QCOMPARE(window.keyEvents.last()->type(), QKeyEvent::KeyRelease); - foreach (const QKeyEvent *event, window.keyEvents) { + for (const QKeyEvent *event : std::as_const(window.keyEvents)) { QCOMPARE(Qt::Key(event->key()), key); QCOMPARE(Qt::KeyboardModifiers(event->modifiers()), modifiers); } @@ -139,7 +137,7 @@ void tst_QKeyEvent::modifiers_data() std::sort(modifierCombinations.begin(), modifierCombinations.end(), orderByModifier); QTest::addColumn("modifiers"); - foreach (const QList combination, modifierCombinations) { + for (const QList &combination : std::as_const(modifierCombinations)) { int keys[4] = {}; Qt::KeyboardModifiers mods; for (int i = 0; i < combination.size(); ++i) {