PyqtSignal and QObject.receivers (..)

I need to check the signal for the presence of the listener before it emits.

class Test(QObject): test = pyqtSignal(str,dict) def run(self): if self.receivers(SIGNAL("test(str,dict)"): self.test.emit('blablabla',{})` 

The signal is connected to the slot to the right and successfully emits signals.
When checking a signature signal, the QObject.receivers() method shows that this signal is not connected.
I realized the reason was the wrong signature, I did not find a method to indicate the exact signature of the signal.

+4
source share
2 answers

The signature for your signal is "test(QString, PyQt_PyObject)" .

Thus, it is obvious that str maps to QString and other types of objects of the native type python, dict , list ... are mapped to the C ++ type PyQt_PyObject .

A list of signal signatures can be obtained through the QMetaObject associated with your object:

 test = Test() metaobject = test.metaObject() for i in range(metaobject.methodCount()): print(metaobject.method(i).signature()) 
+5
source

In pyqt5, SIGNAL is deprecated. It is replaced by the signal attribute of each QObject.

if QObject .receivers ( QObject . signal )> 0:

  print('signal connected') 

To verify that pressing the QPushButton () button connects to any slot

 button = QPushButton() . . if button.receivers(button.clicked) > 0: ..... 
+3
source

All Articles