pythonpysidepyside2

Pyside2 receivers func


For the below 2 examples for receivers functions, the result for the destroyed signal is correct. As I already connect the ObjectNameChanged signal, why the output is 0 ?

self.signal_obj = QObject()
def destroy_slot_handler():
    print("The object is destroyed.")
self.signal_obj.destroyed.connect(destroy_slot_handler)
print(self.signal_obj.receivers(SIGNAL("destroyed()")))

The output is "1"

def name_changed_slot_handler(name):
    print("The name of object is changed.", name)
self.signal_obj.objectNameChanged.connect(name_changed_slot_handler)
print(self.signal_obj.receivers(SIGNAL("objectNameChanged()")))

The output is "0"


Solution

  • objectNameChanged has a QString argument; even if the connected function/slot won't use it, the signal signature still requires that argument.

    If you call the macro with the proper argument type(s), it will work as expected:

    >>> print(self.signal_obj.receivers(SIGNAL("objectNameChanged(QString)")))
    1