metdos
metdos

Reputation: 13929

QTimer stops and starts by itself

Here is how I use QTimer:

QTimer *timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(update()));
timer->setInterval(1000);
timer->start();

Program monitors update() function and prints the current time in it. Normally it works as expected, it prints time at every second, but when program starts to process other jobs, there would be some breaks like 5 to 8 secs.

Qt Documentation mentions about accuracy issues like 1 ms, obviously I have another problem. Any ideas ?

Upvotes: 0

Views: 1075

Answers (2)

Stephen Chu
Stephen Chu

Reputation: 12832

QTimer (and all event-base message deliveries) is not interrupt driven. That means you are not guaranteed you will receive the event right when it's sent. The accuracy describes how the event is triggered, not how it's delivered.

If you are not doing threaded process on long job, call QCoreApplication::processEvents() periodically during the long process to ensure your slot gets called.

Upvotes: 2

Erik
Erik

Reputation: 91270

Your other jobs run for several seconds, and there's no event processing during these. You'd need to thread the jobs in order to get the responsiveness you want.

Upvotes: 0

Related Questions