prevent starting a QTimer with a negative interval
Review Request #120800 - Created Oct. 25, 2014 and submitted
|René J.V. Bertin|
After waking my Mac from (a night's) sleep, I noticed a quickly repeating error message about starting a QTimer with a negative interval. I could trace this to the PausableTimer instance in collectionscheduler.cpp .
The attached patch prevents the error condition by clipping the calculated remaining time interval to 0 .
I've left a debug statement that can of course doesn't need to be committed.
On OS X 10.6.8 with kdelibs 4.14.2 and kdepim* 4.13.3
Thanks for looking into this, runtime warnings bother me too. But is there any point in that debug statement? Debugging? I'm curious too about how the timer could still be active at the time of the pausing, if it was after interval(). Maybe this is because setInterval was called later. But that means testing mStarted.secsTo( mPaused ) at the time of the call to pause() too? Anyway, better finish the debugging (to fully understand the issue) than commit debug output and hope someone else will finish the debugging :-)
indentation of all the new code seems off -- or is that just reviewboard?
That bit (mPaused set to invalid datetime, and mStarted set to "now") happens anyway, so I don't see the relation with the issue? IMO it's confusing to have that in the debug output if it's not related to the issue (remainder being negative)
Somehow this made the negative interval issue come back. Curiously, as with the original code, the warning message is printed much more often upstream by Qt than through the debug message in my previous "else" branch.
I'll try using a temp. variable - it'll be optimised away by the compiler (clang in my case) but might prevent issues with using calling
interval()twice in rapid succession.