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 <allan.jensen@qt.io>
This commit is contained in:
Thiago Macieira 2017-07-05 21:52:52 -07:00
parent bcd19b723a
commit 3509626128

View File

@ -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);
}
/*!