Suppose I have 2 QTimer
objects with 10, 20 as their intervals. And suppose I want to run slot1()
with timer 1 timeout
signal and slot2
with timer 2. So running order of slot1
and slot2
is something like this :
10ms-----20ms-----------30ms----40ms-----
(slot1) (slot1, slot2) (slot1) (slot1, slot2)...
I want to know after 20 milliseconds which one of slot1
& slot2
executes at first? and how can I force the event loop to run slot2
and then slot1
when they have overlap.(slot2
is more important for me to run on time)
There is no guarantee that slots in two timers get called with specific orders. This is because you are starting them in different times and also QTimer
at best has millisecond accuracy by setting this :
timer.setTimerType(Qt::PreciseTimer);
The default is Qt::CoarseTimer
which causes to have an accuracy within 5% of the desired interval.
About your case, if you want to call slot2
and slot1
in order you can call them in a slot connected to a timer with interval of 10 :
void myClass::onTriggered()
{
if(count % 2==0)
slot2();
slot1();
count++;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With