'Is it possible in Qt to stop the execution of a slot in some point until some condition occurs somewhere else? Would condition variables work fine?

I have my slot that does some stuff. Under certain conditions this slot may require to be stopped until some condition occurs somewhere else. How can I achieve this? Yes, of course I could decouple the logic in two slots and arrange connections properly but I was looking for some more elegant work-around. Condition variables came in my mind but, as a newby at using Qt, I don't know whether they would work or not in that I didn't explicitly declare any thread class.



Solution 1:[1]

any QObject has a method for blocking signals that works like a switch allowing to turn OFF - ON the signals the object emit.

here is the doc for this feature:

https://doc.qt.io/qt-5/qobject.html#blockSignals

If block is true, signals emitted by this object are blocked (i.e., emitting a signal will not invoke anything connected to it). If block is false, no such blocking will occur.

you can call it as

for turning OFF the signals:

 ui->myButton->blockSignals(true); 

and for turning ON the signals:

 ui->myButton->blockSignals(false); 

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 ΦXocę 웃 Пepeúpa ツ