Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
I have a program that runs simulations, and every time my results update, a signal is emitted and I show the results in my GUI. This works perfectly if I run my simulations on real-time data (the signal is emitted every couple of minutes).
However, when I run a benchmark on old data that I collected (not real-time anymore), my entire simulation takes about one minute, with all my signals (about 2 million) emitted within this one second. Hence, my GUI updates 2 million times in a single second.
Is there anyway I can drop signals if there are so many emitted in a short time? I'm not sure how the Qt code is implemented, but I assume that with a Qt::QueuedConnection, all emitted signals are added to the end of the queue, and then one-by-one they are taken from the front of the queue and then processed. So the moment it checks for the next signal in the queue, if the queue has more than 1 signal, it should drop all of them and only take the last one.
Disconnecting the signal and only updating the GUI at the end is not an option for me, since other processes rely on continues updates (even if every nth update is dropped).
Is something like this possible?
t3685 last edited by
As far as I know you can't drop signals like you are describing. Your best bet would be to implement a way to not having to send so many signals. For example you could a timer that only periodically checks your data and then emit the signal.
Queued connections are only added to a queue if the signal emitter and the signal receiver live in different threads, if your emitter lives in the same thread as your gui the slots are executed immediately.
Hmm, hoped there would be a clean solution. Just for interest sake, what exactly does QCoreApplication::removePostedEvents() do? Some other post suggested using this function for something similar. However, it doesn't seem to work in my situation.
t3685 last edited by
More information here:
In my opinion should consider just not sending as many signals as this is the main reason for your performance problems.
All you need to do is modify the code where you retrieve your real time data and have some logic to reduce the number of emissions.
Also it does not seem efficient to do work to process the real-time data only to drop it again moments later.
Anyway, good luck!
Yip, did that now. Just emitted every 100th signal. Thanks.