How to check signal emit finished in python



  • Hi,
    I have created one signal in python using pyside. I'm connecting with that signal 3 times with 3 different methods. when i emit this signal, it has to execute these 3 methods.
    It works perfectly fine.

    ValueChanged = QtCore.Signal(list)

    ValueChanged.connect(method1)
    ValueChanged.connect(method2)
    ValueChanged.connect(method3)

    valueChanged.emit([1,2,3])

    But i would like to know anyway that 3 methods have been executed or not, i.e the status of signal ( signal is in emitting state, emitted state ).
    a) I don't prefer putting bool flag in every methods and track it. b) i can't put some regular interval also bz each method would take its own time.

    How do i know signal emitted all connected methods ?



  • There is QSignalSpy in Qt. I'm not sure about python equivalent. Please check if this helps.


  • Lifetime Qt Champion

    Hi,

    QSignalSpy is only meant to be used in unit tests not production code.

    That's more a design question: if all method must called why not have method1 calling method2 etc. ?



  • Hi. Thanks for reply. Actually i would connect to signal based on some conditions and also not in same place. so I can't call method2 inside method1. Even if i do so, how will i know that this method ( method1) has been executed or not without any bool flag.



  • very simple way: global int variable. Increment it when a method is called. When 3, all three methods have been called. Clear the variable whenever a method is called and the variable is 3.
    As simple as that. Is it fine for you?

    Also, I'm not sure if anything can go wrong but once a signal is emitted all slots connected to it will be called sooner or later. So maybe, if you say these you connect to those signals based on conditions, you need something to track whether the slots were actually connected to the signal instead of tracking if all slots are triggered by the signal. This sounds like failure-ready design to me and I would definitely look for an alternative solution.


Log in to reply
 

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