Clear pending signal
-
Hi,
I have a QObject which emits signal which is directly (only one thread in application) connected to many receiver QObjects' slots. I emit signal and then slots are called one by one by Qt. In some slot I want to tell that subsequent slots should not be called (because the signal was served in that particular QObject).Is that possible?
-
Hi @MartinD
What about
disconnect
your signal?Like
connect
static function you have actually a staticdisconnect
functionhttp://doc.qt.io/qt-5/qobject.html#disconnect
Hope this can help !
void YourClass::onSomeSlot { //Do somethings . . . //DISCONNECT SIGNAL disconnect(yourObject,SIGNAL(triggered()),this,SLOT(yourSlot())); }
-
Hi,
I have a QObject which emits signal which is directly (only one thread in application) connected to many receiver QObjects' slots. I emit signal and then slots are called one by one by Qt. In some slot I want to tell that subsequent slots should not be called (because the signal was served in that particular QObject).Is that possible?
-
Is it better to use the event system in this case?
I think the signals&slots mechanism is not designed to be used this way. Signals and slots should not know anything about outside world, this way objects will not be tied together.
maybe insert an intermediate object between the object that emit the signal and objects that have slot connected to the signal to deal with it, or using event system and filter the event a good choice?
-
Hi
I agree with @Flotisable that signals are not designed for such dispatcher design.
You could have a man in the middle class that gets the signal and then
call one or more connected objects but a raw design with connect only will be clumsy.
Your thread could do it
but Im wondering why you connect many up , if only one should handle the signal? -
Hi,
I have a QObject which emits signal which is directly (only one thread in application) connected to many receiver QObjects' slots. I emit signal and then slots are called one by one by Qt. In some slot I want to tell that subsequent slots should not be called (because the signal was served in that particular QObject).Is that possible?
to add to @mrjj and @Flotisable , because the idea of using a 'signal helper' is the correct one.
If, you connect multiple slots to a single Signal it is not guaranteed that slots are always called in the exact same order.
Even so it seems most of the time, that the "First connect-statement" is also executed first when the signal comes. This is not the regular case, the execute order depends on many different things, with compile order being a minor one.