pythonqtpyqtsignalsslot

How to find if a signal is connected to anything


Is there a way to tell if a signal is already connected to a function?

i.e I want to see if signals.siSelectionChange is connected to anything

signals.siSelectionChange.connect( self.SelAsSiAssets )

Solution

  • You can use QObject.receivers to get the count of connected functions. I used it as follows, in the closeEvent() of a QWidget, I use as window:

        receiversCount = self.receivers(QtCore.SIGNAL("siSelectionChanged()"))
        if receiversCount > 0:
            self.sigChanged.disconnect()
    

    Note that the signature in the argument string must match the real signature.