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 static disconnect function

    http://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()));
    
    }
    


  • @MartinD

    To add to @mostefa

    adding the parameter Qt::ConnectionType ,with Qt::UniqueConnection might also help in your situation



  • 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?


  • Qt Champions 2016

    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?



  • @MartinD

    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.



  • Thanks everybody. I will leave my idea and rather use Qt event system.


  • Qt Champions 2016

    @MartinD
    well you can also just drop the connects and call manually
    MetaObject::invokeMethod( textEdit, "append", Qt::QueuedConnection, Q_ARG( QString, myString ) );
    if u already have the slots etc.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.