Get the App
SLTechnology News&Howtos  ›  Development  › 

How to disconnect and connect the signal and slot with python

Shulou Source: shulou.com Published: 2022-06-01 04:10:18 09月25日 Update

This article mainly introduces how to achieve python signal and slot disconnection and connection, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor with you to understand.

Disconnection and connection between signal and slot

Sometimes for some reason, you want to disconnect a signal from a slot function temporarily or permanently. That's what you're talking about.

Generally speaking, adding dis before connect means unbinding: disconnect.

Examples are as follows

From PyQt5.QtCore import QObject,pyqtSignalclass SignalClass (QObject): # declare a signal with no parameters signal1=pyqtSignal () # declare a signal with an int type parameter signal2=pyqtSignal (int) def _ init__ (self,parent=None): super (SignalClass Self). _ init__ (parent) # connects the signal1 signal to two slot functions self.signal1.connect (self.sig1Call) self.signal1.connect (self.sig2Call) # connects the signal2 signal to the signal 1 self.signal2.connect (self.signal1) # transmit signal self.signal1.emit () self.signal2.emit (1) # disconnects the relationship between the signal and the slot function self.signal1.disconnect (self.sig1Call) self.signal1 .disconnect (self.sig2Call) self.signal2.disconnect (self.signal1) # binding signal and slot function self.signal1.connect (self.sig1Call) self.signal2.connect (self.sig1Call) # signal Emission self.signal1.emit () self.signal2.emit (1) # output signal 1 Emission def sig1Call (self): print ('signal-1 emit') # output signal 2 Emission def sig2Call (self): print (' signal-2 Emit') if _ _ name__ = ='_ main__': signal=SignalClass ()

Thank you for reading this article carefully. I hope the article "how to disconnect and connect python signals and slots" shared by the editor will be helpful to everyone. At the same time, I also hope that you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Tags: Signal function article emission parameter that is output two value interest content reason at the same time example meaning more sometimes friend knowledge type Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker vpn NVidia Xiaomi Huawei