From ea24142ab5d8da7c47a7075696b5b8227ddf6458 Mon Sep 17 00:00:00 2001 From: Ahmad Samir Date: Mon, 14 Aug 2023 02:51:17 +0300 Subject: [PATCH] tst_QPrintDevice: compile with QT_NO_FOREACH The loop was iterating over a temporary, so it couldn't have changed it. Store the container in a local const variable and port to ranged-for. Drive-by change: don't call ps->availablePrintDeviceIds() multiple times. Task-number: QTBUG-115839 Change-Id: If2cabec68040dc7096acf0b7ddeff72d7c8c7750 Reviewed-by: Volker Hilsheimer --- .../kernel/qprintdevice/tst_qprintdevice.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/tests/auto/printsupport/kernel/qprintdevice/tst_qprintdevice.cpp b/tests/auto/printsupport/kernel/qprintdevice/tst_qprintdevice.cpp index 2221f9d9205..fefce34d990 100644 --- a/tests/auto/printsupport/kernel/qprintdevice/tst_qprintdevice.cpp +++ b/tests/auto/printsupport/kernel/qprintdevice/tst_qprintdevice.cpp @@ -1,8 +1,6 @@ // Copyright (C) 2014 John Layt // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 -#undef QT_NO_FOREACH // this file contains unported legacy Q_FOREACH uses - #include #include @@ -27,16 +25,17 @@ void tst_QPrintDevice::basics() QSKIP("Could not load platform plugin"); QString defaultId = ps->defaultPrintDeviceId(); + const QStringList availableIds = ps->availablePrintDeviceIds(); if (defaultId.isEmpty()) { qDebug() << "No default printer found"; } else { - QVERIFY(ps->availablePrintDeviceIds().contains(defaultId)); + QVERIFY(availableIds.contains(defaultId)); } - qDebug() << "Available Printer IDs :" << ps->availablePrintDeviceIds(); + qDebug() << "Available Printer IDs :" << availableIds; // Just exercise the api for now as we don't know what is installed - foreach (const QString id, ps->availablePrintDeviceIds()) { + for (const QString &id : availableIds) { QPrintDevice printDevice = ps->createPrintDevice(id); const char quote = id == defaultId ? '*' : '"'; qDebug().noquote().nospace() << "\nCreated printer " << quote << id