From ef7b641a3cf267e256468f9a6269a9bcf7656aa9 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Fri, 8 Mar 2024 11:23:10 +0100 Subject: [PATCH] QTest::qWaitFor: scope a variable tighter When fa296ee1dcf4c16fb6f242cf08949485e499fec3 ported this function from int timeout to QDeadlineTimer, the need to keep this variable outside the do-while so it could be checked in the loop exit condition fell away. Moving the definition of the variable to the first (and only) assignment makes the code clearer and the variable a constant. Amends fa296ee1dcf4c16fb6f242cf08949485e499fec3. Pick-to: 6.7 Change-Id: I7a0fe01dc68ff140beeb0e76b141c84d4bd28458 Reviewed-by: Ahmad Samir --- src/corelib/kernel/qtestsupport_core.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/corelib/kernel/qtestsupport_core.h b/src/corelib/kernel/qtestsupport_core.h index 1507c94783..0050bcee9b 100644 --- a/src/corelib/kernel/qtestsupport_core.h +++ b/src/corelib/kernel/qtestsupport_core.h @@ -30,7 +30,6 @@ qWaitFor(Functor predicate, QDeadlineTimer deadline = QDeadlineTimer(std::chrono using namespace std::chrono; - auto remaining = 0ms; do { // We explicitly do not pass the remaining time to processEvents, as // that would keep spinning processEvents for the whole duration if @@ -49,7 +48,7 @@ qWaitFor(Functor predicate, QDeadlineTimer deadline = QDeadlineTimer(std::chrono continue; } - remaining = ceil(deadline.remainingTimeAsDuration()); + const auto remaining = ceil(deadline.remainingTimeAsDuration()); if (remaining == 0ms) break;