PDA

View Full Version : how to use Multiple timers?



qtlinuxnewbie
2nd April 2010, 13:28
HI,

i want to use multiple timers.
for example to do some task shuld be done by using first timer interval and another task should be done for the second timer interval,
actually for single timer i was using starttimer(time interval)
so my Question is how to start second timer , i mean how to initiate the timer and distinguish from the first timer

Could any one give me some sample code or any examples which are using multiple timers.

Thnks in advance,,,
QtlinuxNewbie

wysota
2nd April 2010, 13:44
See QTimer.

qtlinuxnewbie
2nd April 2010, 14:07
i was using timer event. and doing a task for some time interval
now i want to do another task with different time interval...
..
hope u understood...

Thnx

Lesiok
2nd April 2010, 14:15
Create as many instances of QTimer as You need. And run every one with different timeout.

qtlinuxnewbie
2nd April 2010, 14:18
ok thank you and shuld i run single timer event with different timer instances or multiple timer events???

Lesiok
2nd April 2010, 14:27
I miss what is a problem.
Simply You creates many QTimers and connect every of them to another slot.
Just read QTimer class reference (http://doc.trolltech.com/4.6/qtimer.html)

wysota
2nd April 2010, 14:30
You can have multiple timer events with different intervals. See QTimerEvent and QObject::startTimer() (especially the return value of the latter)

mahi6a1985
20th September 2012, 11:24
I miss what is a problem.
Simply You creates many QTimers and connect every of them to another slot.
Just read QTimer class reference (http://doc.trolltech.com/4.6/qtimer.html)

Hi Lesiok,

I had done what you explained. But it was delaying the process.
means 6 Qtimers created and connected to 6 diff slots with different timeouts.

but i am the timers are getting delayed. As per my application i need to run all the timers at a time.

sample code of mine is --



1st timer -
timer_HMIScrLvl4 = new QTimer(this);
connect(timer_HMIScrLvl4, SIGNAL(timeout()), this, SLOT(update_HMIScrLvl4()));
timer_HMIScrLvl4->setInterval(100);
2nd timer -
Timer_failure_display = new QTimer(this);
connect(Timer_failure_display, SIGNAL(timeout()), this, SLOT(failure_display()));
Timer_failure_display->setInterval(250);
3rd timer -
Timer_footer = new QTimer(this);
connect(Timer_footer, SIGNAL(timeout()), this, SLOT(footer()));
Timer_footer->setInterval(250);
4th timer -
Timer_diagonostic_refresh = new QTimer(this);
connect(Timer_diagonostic_refresh, SIGNAL(timeout()), this, SLOT(diagonostic_refresh()));
Timer_diagonostic_refresh->setInterval(50);
5th Timer -
Timer_information_refresh = new QTimer(this);
connect(Timer_information_refresh, SIGNAL(timeout()), this, SLOT(information_refresh()));
Timer_information_refresh->setInterval(25);
6th timer -
Timer_footer = new QTimer(this);
connect(Timer_footer, SIGNAL(timeout()), this, SLOT(footer()));
Timer_footer->setInterval(250);


1st & 2nd timers are the main timers i should not wanted them to be delayed, they should run at a time.

Thanks in Advance.

Forgive me if any thing i posted is against to the rules if the forum.

plzz help me if possible as early as possible.

Lesiok
21st September 2012, 09:01
Hi Lesiok,

I had done what you explained. But it was delaying the process.
means 6 Qtimers created and connected to 6 diff slots with different timeouts.

but i am the timers are getting delayed. As per my application i need to run all the timers at a time.

sample code of mine is --



1st & 2nd timers are the main timers i should not wanted them to be delayed, they should run at a time.

Thanks in Advance.

Forgive me if any thing i posted is against to the rules if the forum.

plzz help me if possible as early as possible.

Are you sure you read the documentation? I think not. Quote from the QTimer documentation :
Timers will never time out earlier than the specified timeout value and they are not guaranteed to time out at the exact value specified. In many situations, they may time out late by a period of time that depends on the accuracy of the system timers.
.....
If Qt is unable to deliver the requested number of timer clicks, it will silently discard some.