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)));