PyQt5 信号和槽多对多与断开连接
from PyQt5.QtCore import QObject, pyqtSignal
'''
PyQt5 信号和槽多对多与断开连接
'''
class NNSignalDemo(QObject):
signal1 = pyqtSignal()
signal2 = pyqtSignal(int)
signal3 = pyqtSignal()
def __init__(self):
super().__init__()
# 同一个槽关联多个信号
self.signal1.connect(self.call1)
self.signal1.connect(self.call11)
# 同一个信号给多个槽
self.signal3.connect(self.call1)
self.signal1.emit()
self.signal2.connect(self.signal1)
self.signal2.emit(2) # 实际触发了信号1
self.signal1.disconnect(self.call1)
self.signal1.disconnect(self.call11)
self.signal2.disconnect(self.signal1)
self.signal1.emit()
self.signal2.emit(100)
self.signal3.emit()
def call1(self):
print("call1 emit")
def call11(self):
print("call11 emit")
def call2(self,val):
print("call2 emit:",val)
if __name__ == '__main__':
nnSignal = NNSignalDemo()