开发者

pyqtSignal and QObject.receivers(..)

I need to check the signal for the presence of the listener, before it is emitted.

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 right and successfully emits signals.

W开发者_如何学Gohen checking the signature signal, the method QObject.receivers() shows that this signal is not connected.

I understood, reason was incorrect signature, I did not find a method, to specify the faithful signature of signal.


In pyqt5 SIGNAL is deprecated. It is replaced with signal attribute of each QObject

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

    print('signal connected')

To Check QPushButton signal clicked() is connected to any slot

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


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

So obviously, str is mapped to QString and other native python object types, dict, list... are mapped to the C++ type PyQt_PyObject.

The 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())
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜