From bf7eff01884017170708385c994a5de7b4dfd49c Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Mon, 11 Mar 2024 12:55:36 +0100 Subject: [PATCH] QTest::qWaitFor: scope std::chrono using directive tighter ... moving it away from between a comment and the C++ code the comment pertains to. Change-Id: I56b3ded01d1800bae19121e4b9340d0c43f1da85 Reviewed-by: Edward Welbourne Reviewed-by: Ahmad Samir (cherry picked from commit c1d1437b4a8609f4b6e7eb5f39352d4951b4f507) --- src/corelib/kernel/qtestsupport_core.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/corelib/kernel/qtestsupport_core.h b/src/corelib/kernel/qtestsupport_core.h index ac58898188d..1de17a6b2e6 100644 --- a/src/corelib/kernel/qtestsupport_core.h +++ b/src/corelib/kernel/qtestsupport_core.h @@ -28,8 +28,6 @@ qWaitFor(Functor predicate, QDeadlineTimer deadline = QDeadlineTimer(std::chrono // qWait() is expected to spin the event loop at least once, even when // called with a small timeout like 1ns. - using namespace std::chrono; - do { // We explicitly do not pass the remaining time to processEvents, as // that would keep spinning processEvents for the whole duration if @@ -43,6 +41,8 @@ qWaitFor(Functor predicate, QDeadlineTimer deadline = QDeadlineTimer(std::chrono if (predicate()) return true; + using namespace std::chrono; + if (const auto remaining = deadline.remainingTimeAsDuration(); remaining > 0ns) qSleep((std::min)(10ms, ceil(remaining)));