From 923e08132cfd0c9140e705a7f0f27b3432f94695 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Sun, 17 Dec 2017 01:05:14 +0100 Subject: [PATCH] tst_QActionGroup: avoid Java-style iterators They are going to be deprecated soon. Use a lambda to mimic the adjacent addActions() calls. Also, I didn't want to add a scope or extend the lifetime of the return value of actions() until the end of the function, and for (QAction *action : actGroup.action()) would detach. I'd've made it a helper function, but it's used only once, so... a lambda. Change-Id: I2b3aae463036fd61a9cca7b4ef991b8752869bf3 Reviewed-by: Giuseppe D'Angelo --- .../kernel/qactiongroup/tst_qactiongroup.cpp | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/tests/auto/widgets/kernel/qactiongroup/tst_qactiongroup.cpp b/tests/auto/widgets/kernel/qactiongroup/tst_qactiongroup.cpp index 52ca10d31f8..0ba3cedf16f 100644 --- a/tests/auto/widgets/kernel/qactiongroup/tst_qactiongroup.cpp +++ b/tests/auto/widgets/kernel/qactiongroup/tst_qactiongroup.cpp @@ -166,24 +166,22 @@ void tst_QActionGroup::separators() separator->setSeparator(true); actGroup.addAction(separator); - QListIterator it(actGroup.actions()); - while (it.hasNext()) - menu.addAction(it.next()); + menu.addActions(actGroup.actions()); QCOMPARE((int)menu.actions().size(), 2); - it = QListIterator(actGroup.actions()); - while (it.hasNext()) - menu.removeAction(it.next()); + const auto removeActions = [&menu](const QList &actions) { + for (QAction *action : actions) + menu.removeAction(action); + }; + removeActions(actGroup.actions()); QCOMPARE((int)menu.actions().size(), 0); action = new QAction(&actGroup); action->setText("test two"); - it = QListIterator(actGroup.actions()); - while (it.hasNext()) - menu.addAction(it.next()); + menu.addActions(actGroup.actions()); QCOMPARE((int)menu.actions().size(), 3); }