From 35096261282bfb2d66373d290dfa35b993158bb8 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Wed, 5 Jul 2017 21:52:52 -0700 Subject: [PATCH] QDeadlineTimer: round milliseconds up instead of down Code like: QElapsedTimer timer; timer.start(); QTest::qWait(30); QVERIFY(timer.elapsed() >= 30); is failing, because qWait sleeps in increments of 10 ms and the last chunk may be off by less than one millisecond, so we end up sleeping too little and thus returning before 30 ms have elapsed. This matches the QElapsedTimer::elapsed() code that rounds down: return nsecsElapsed() / Q_INT64_C(1000000); Task-number: QTBUG-61741 Change-Id: Ic3a088f9f08a4fd7ae91fffd14cea4a91d3f51a8 Reviewed-by: Allan Sandfeld Jensen --- src/corelib/kernel/qdeadlinetimer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/corelib/kernel/qdeadlinetimer.cpp b/src/corelib/kernel/qdeadlinetimer.cpp index a2ec813f11..ae4ffdcefc 100644 --- a/src/corelib/kernel/qdeadlinetimer.cpp +++ b/src/corelib/kernel/qdeadlinetimer.cpp @@ -420,7 +420,7 @@ void QDeadlineTimer::setTimerType(Qt::TimerType timerType) qint64 QDeadlineTimer::remainingTime() const Q_DECL_NOTHROW { qint64 ns = remainingTimeNSecs(); - return ns <= 0 ? ns : ns / (1000 * 1000); + return ns <= 0 ? ns : (ns + 999999) / (1000 * 1000); } /*!