[SOLVED] QTimer remainingTime() always returns 0
-
Hello,
I have a problem with the remainingTime() function of QTimer. It always returns 0, even if I call it immediately after having started a timer. For example:
@timer = new QTimer (this);
timer->setSingleShot (true);
timer->start (3000);
qDebug () << "Remaining time: " << timer->remainingTime ();@This always prints "Remaining time: 0" on the console, though the timer still runs for 3 seconds. In the documentation, it says that the remainingTime() function only returns 0 when the timer is overdue, but that's not the case here. Am I doing something wrong?
Thanks.
-
Thank you for your answer. The remainingTime() function also returns 0 when I call it later, for example 2 seconds after starting the timer, where it should give me a value around 1000 but it returns 0.
I wanted to use this value to implement a pause button in a game, because QTimer has no pause and resume functions. I don't know other ways to realize this, so any help is appreciated.
-
First of all: please file a bug report.
Then, perhaps you can use a QElapsedTimer to figure out the run time? You may considder creating your own (temporary) class that simply wraps a QTimer and a QElapsedTimer and mimics the QTimer API. Then, you can use that as a drop-in replacement to QTimer while this bug is not fixed in Qt yet.
-
Yesterday I tried your solution with an own timer class, which uses a QElapsedTimer to calculate the remaining time and a QTimer for the timeout signal. This worked too, but the "remaining time" that I got was not really accurate (haven't checked my code for errors though).
But I don't need it anymore, because the problem has been solved with a simple reboot. They suggested it to me when I filed the bug report. It is still strange that something like this can happen, it didn't work for me for quite some time. Now I'm glad that it has been resolved. Thank you again for your help!
-
This is the bug report: