Solved A problem with single slot connected to multiple signals
-
@Oleg_Suf
Hi
If you remove mySleep(2); does it still come out of order ? -
@mrjj said in A problem with single slot connected to multiple signals:
@Oleg_Suf
Hi
If you remove mySleep(2); does it still come out of order ?If I remove mySleep(2) the order becomes correct. But in real task some PCs do have a certain latency, so I wish I could get rid of it in my work project, but...
-
Ok i was wondering the the local event loop would interfere with
the regular and it seems it does.If they perform heavy task in real world, you should rather
use threads as not to hang the main thread. -
Set some delay between the timers.
void Dialog::on_pushButton_clicked()
{
tmr1->start(1);
tmr2->start(2);
tmr3->start(3);
} -
@Vinod-Kuntoji said in A problem with single slot connected to multiple signals:
Set some delay between the timers.
I would love to do this, but it's just a model example, real app signals come from hardware, and I'm unable to affect its reaction time.
I guess I have two choises then - 1) Try to reduce the slot execution time by all means; 2) Perform every new task in separate thread and use mutex (I'd really wish to avoid that)) -
@Oleg_Suf
You could wait some ticks before stoppingala something like
(for testing)void Dialog::on_TimerTick()
{
static int tickcc=1;
if (tickcc == 1)
Print(QString("Started ") + QObject::sender()->objectName());
else if (tickcc > 4 ) {
Print(QString("Stopped ") + QObject::sender()->objectName());
tickcc =0;
}
tickcc++;
} -
@Oleg_Suf said in A problem with single slot connected to multiple signals:
And I can't understand
how to fix it.You can't reliably change that. A timer will fire the first opportunity it has (i.e. when control returns to the event loop) but there's no guarantee for ordering it depends on which timers have timed out at the time of check, and which haven't. In any case you should not depend on the order of appearance of signal emissions/slot calls.
-
Hi,
Can you explain how your application is supposed to react to these hardware "signals" ? And also why is it the same slot that is called for what seems to be different hardware ?
-
@SGaist said:
Can you explain how your application is supposed to react to these hardware "signals" ?
Hardware sends data, my program processes these packages of data in the same way every time, and every time responds;
And also why is it the same slot that is called for what seems to be different hardware ?
No, hardware is the same, it just triggers very fast
-
I don't follow, why would you need to ensure a specific order of the slot execution/signal emission then?
-
@kshegunov said:
I don't follow, why would you need to ensure a specific order of the slot execution/signal emission then?
Because order matters to user. Anyway, I concluded, that if I can't increase time interval between signals emittions, I have to decrease slot execution time, there is no other way to ensure consistency in this case. The given example is simplified, but in original task, I ended up performing data processing (which was shown as "mySleep(2);") in worker thread, and all GUI things (which were shown as Print() methods) - in main thread.
Thanks to everyone -
What order is that ?
Are you also ensuring that the hardware sends its data always at the same pace and in the same order ?