Here is a a part of the documentation of Qt's QElapsedTimer:

bool QElapsedTimer::hasExpired(qint64 timeout) const

Returns true if this QElapsedTimer has already expired by timeout milliseconds (that is, more than timeout milliseconds have elapsed). The value of timeout can be -1 to indicate that this timer does not expire, in which case this function will always return false.

Shouldn't it rather be implemented as more than timeout -1 milliseconds have elapsed ?

EDIT: My idea about More than timeout -1 is definitely incorrect. What I really wanted to ask was wether the explanation of more than may be incorrect and I think it precisely should be equal or more than.

  • 1
    Questions that ask why some software was designed the way it is are a bit difficult: we aren't the designers, we don't really know. But this documented behaviour seems perfectly fine to me, and is shared by many other timer implementations. Could you explain why you think that one millisecond should be ignored, i.e. why hasExpired(1) should always and immediately be true? Why one millisecond, and not one second or microsecond?
    – amon
    Sep 8, 2018 at 8:07
  • It shouldn't. My intention for asking was more like: Think about waiting for, e.g., 100 ms and an internal timer precision of 1 ms. I'd expect hasExpired() to return true after 100 ms and not after 101. In that particular moment when the timer value reaches 100 then it already has expired.
    – FlKo
    Sep 8, 2018 at 16:02

1 Answer 1


No. Because then a 1ms timer would elapse after 0.0000001ms

I guess "x or more milliseconds" might be better wording/implementation but whats the precision of the underlying measurement?

Also consider time spans. Say I have a start time of 0 and an end time of 100. Is 100 within the time span or do I say that the span is over when t > 100

If I say 100 is within the span, then 0 must be outside it. Otherwise I cant put spans back to back.

  • Yes, X or more is what I think would be correct. When I implement timers manually I always compare the current value <= against the timeout value.
    – FlKo
    Sep 8, 2018 at 16:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.