How to call QObject.receivers() and QObject.isSignalConnected() in the right way?
-
Hi all,
Could anyone please provide a working example of how to use eitherQObject.receivers()orQObject.isSignalConnected()in python code?I've found some examples written in C++ and some old topics for PyQt4... - maybe I'm stupid enough but I can't figure out how to do the same in python (I tried to play with
QMetaObjectand other things but without any sign of success. So I need help...) -
The best option I found for
isSignalConnected()is:m_header = header.metaObject() header.isSignalConnected(m_header.method(m_header.indexOfSignal("sectionDoubleClicked(int)")))It works, but... looks a bit strange for me...
-
Hi all,
Could anyone please provide a working example of how to use eitherQObject.receivers()orQObject.isSignalConnected()in python code?I've found some examples written in C++ and some old topics for PyQt4... - maybe I'm stupid enough but I can't figure out how to do the same in python (I tried to play with
QMetaObjectand other things but without any sign of success. So I need help...)Just check the example given in the documentation
valueChangedSignal = QMetaMethod.fromSignal(MyObject.valueChanged) if isSignalConnected(valueChangedSignal): data = QByteArray() data = get_the_value() # expensive operation valueChanged.emit(data) -
Just check the example given in the documentation
valueChangedSignal = QMetaMethod.fromSignal(MyObject.valueChanged) if isSignalConnected(valueChangedSignal): data = QByteArray() data = get_the_value() # expensive operation valueChanged.emit(data)@Pl45m4 , I tried it. Have it worked for you?
I have:
from PySide6.QtCore import QMetaMethod
signal = QMetaMethod.fromSignal(view_header.sectionDoubleClicked)
and it fails with:
AttributeError: type object 'PySide6.QtCore.QMetaMethod' has no attribute 'fromSignal'
This is the reason for my question. -
The best option I found for
isSignalConnected()is:m_header = header.metaObject() header.isSignalConnected(m_header.method(m_header.indexOfSignal("sectionDoubleClicked(int)")))It works, but... looks a bit strange for me...
-
S StarterKit has marked this topic as solved on