Skip to main content
Updated to reflect debugging
Source Link
Ernest3.14
  • 1k
  • 11
  • 22

Non-singleshot QTimer only firescounts down once

EDIT 3: When I first asked this question I thought it was because the QTimer was only firing once; however it turned out to be because I was observing it based on its remainingTime() member. It turns out the real problem is that remainingTime() counts down to 0 only once (and the timeout() signal is indeed firing multiple times).


I have a single-threaded Qt application, which has a timer that needs to be repeatedly called. I also have a progress bar to display how much time is left in the main timer, and the progress bar is updated every 40ms by another timer.

Non-singleshot QTimer only fires once

I have a single-threaded Qt application, which has a timer that needs to be repeatedly called. I also have a progress bar to display how much time is left in the main timer, and the progress bar is updated every 40ms by another timer.

Non-singleshot QTimer only counts down once

EDIT 3: When I first asked this question I thought it was because the QTimer was only firing once; however it turned out to be because I was observing it based on its remainingTime() member. It turns out the real problem is that remainingTime() counts down to 0 only once (and the timeout() signal is indeed firing multiple times).


I have a single-threaded Qt application, which has a timer that needs to be repeatedly called. I also have a progress bar to display how much time is left in the main timer, and the progress bar is updated every 40ms by another timer.

Added a better example
Source Link
Ernest3.14
  • 1k
  • 11
  • 22

EDIT 2: I added the following code to the end of update_progress() to further illustrate what is happening:

    qDebug() << "Active: " << timer_capture->isActive();
    qDebug() << "Single shot: " << timer_capture->isSingleShot();
    qDebug() << "Remaining ticks:" << timer_capture->remainingTime() <<
                " / " << timer_capture->interval() << "\n";

The output I'm getting is:

Active:  true
Single shot:  false
Remaining ticks: 1496  /  15000 

Active:  true
Single shot:  false
Remaining ticks: 996  /  15000 

Active:  true
Single shot:  false
Remaining ticks: 494  /  15000 

Active:  true
Single shot:  false
Remaining ticks: 3  /  15000 

Active:  true
Single shot:  false
Remaining ticks: 0  /  15000 

Active:  true
Single shot:  false
Remaining ticks: 0  /  15000 

(ad infinitum)

EDIT 2: I added the following code to the end of update_progress() to further illustrate what is happening:

    qDebug() << "Active: " << timer_capture->isActive();
    qDebug() << "Single shot: " << timer_capture->isSingleShot();
    qDebug() << "Remaining ticks:" << timer_capture->remainingTime() <<
                " / " << timer_capture->interval() << "\n";

The output I'm getting is:

Active:  true
Single shot:  false
Remaining ticks: 1496  /  15000 

Active:  true
Single shot:  false
Remaining ticks: 996  /  15000 

Active:  true
Single shot:  false
Remaining ticks: 494  /  15000 

Active:  true
Single shot:  false
Remaining ticks: 3  /  15000 

Active:  true
Single shot:  false
Remaining ticks: 0  /  15000 

Active:  true
Single shot:  false
Remaining ticks: 0  /  15000 

(ad infinitum)

clarified why I could narrow down the scope of the issue
Source Link
Ernest3.14
  • 1k
  • 11
  • 22

EDIT: To clarify, I am sure that all my other logic is functioning correctly, because I can see in the debugger that:

  • timer_capture.isSingleShot() is false
  • timer_capture.remainingTime() is 0
  • timer_capture.isActive() is true
  • all results of calculations are correct (e.g. time_passed)

And I can also see that the countdown works once and then stops.


EDIT: To clarify, I am sure that all my other logic is functioning correctly, because I can see in the debugger that:

  • timer_capture.isSingleShot() is false
  • timer_capture.remainingTime() is 0
  • timer_capture.isActive() is true
  • all results of calculations are correct (e.g. time_passed)

And I can also see that the countdown works once and then stops.

clarified why one timer works
Source Link
Ernest3.14
  • 1k
  • 11
  • 22
Loading
Source Link
Ernest3.14
  • 1k
  • 11
  • 22
Loading