Answer the question
In order to leave comments, you need to log in
Is there any way to tell Qt that for a particular object it is temporarily not necessary to call a slot (like a pause)?
Greetings!
Let's say there are two separate threads. Thread A generates a signal with some parameters, to which thread B is subscribed, of type Qt::QueuedConnection.
Suppose, for some reason, thread B starts to process too long and then unprocessed signals accumulate in the queue (inside Qt).
Question: how to make it clear to Qt that the slots of a particular object should not be called now and ignored? Of type blockSignal, but only slots. Yes, you can connect / disconnect every time, but it smacks more like a crutch.
Answer the question
In order to leave comments, you need to log in
It is worth remembering that the queue is accumulated in each thread separately, the sender puts them there.
So it is not the signals that accumulate, but the slot call queue.
Therefore, you can block only new signals.
And the question is, why block them in one thread if it reaches another?
If the task is to optimize memory, then you can send a shared pointer with a constant class to both slots.
As an option, connect signals via Qt::DirectConnection instead of Qt::QueuedConnection
And call another, local signal in the slot, which is connected with Qt::QueuedConnection to its own class.
Use for examplestd::atomic<qint64>
in the sender's members, and before starting the threads, pass them a constant pointer to it. With each new send, the sender adds 1 to this number (you must remember to reset it to zero when a certain limit is reached, 1 billion for example). And on the side of the slots in the processing of the Qt::QueuedConnection slot, store its value in a copy of the number in the members of the stream, also atomic. Thus, in the Qt::DirectConnection slot, you can find out about the queue number of a particular thread and, under the conditions you need, ignore its forwarding further.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question