Restore qWait() implementation

qWait() and qWaitFor() have one subtle difference in behavior,
where qWait passes the remaining time to processEvents() and
qWaitFor() does not. This lead to instability on timing
sensitive tests on macOS.

Amends 1abea5f5f1

Change-Id: I20f516813ca67d9e86de468c4403e475f08edc26
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
This commit is contained in:
Lars Knoll 2020-09-13 13:15:56 +02:00
parent 127fb8bb55
commit 46c1e60989
2 changed files with 21 additions and 4 deletions

View File

@ -105,5 +105,25 @@ Q_CORE_EXPORT void QTest::qSleep(int ms)
\sa QTest::qSleep(), QSignalSpy::wait()
*/
Q_CORE_EXPORT void QTest::qWait(int ms)
{
// Ideally this method would be implemented in terms of qWaitFor, with
// a predicate that always returns false, but due to a compiler bug in
// GCC 6 we can't do that.
Q_ASSERT(QCoreApplication::instance());
QDeadlineTimer timer(ms, Qt::PreciseTimer);
int remaining = ms;
do {
QCoreApplication::processEvents(QEventLoop::AllEvents, remaining);
QCoreApplication::sendPostedEvents(nullptr, QEvent::DeferredDelete);
remaining = timer.remainingTime();
if (remaining <= 0)
break;
QTest::qSleep(qMin(10, remaining));
remaining = timer.remainingTime();
} while (remaining > 0);
}
QT_END_NAMESPACE

View File

@ -88,10 +88,7 @@ Q_REQUIRED_RESULT static bool qWaitFor(Functor predicate, int timeout = 5000)
return predicate(); // Last chance
}
inline void qWait(int ms)
{
(void)qWaitFor([]() { return false; }, ms);
}
Q_CORE_EXPORT void qWait(int ms);
} // namespace QTest