from PyQt5.QtCore import *
class MyTypeSignal(QObject):
# 定义一个信号
sendmsg = pyqtSignal(object)
# 发送3个参数的信号
sendmsg1 = pyqtSignal(str, int, int)
def run(self):
self.sendmsg.emit("hello PyQt5")
def run1(self):
self.sendmsg1.emit("hello world", 6, 7)
class MySlot(QObject):
def get(self, msg):
print("信息:" + msg)
def get1(self, msg, a, b):
print("信息:" + msg, "今天是{}月{}日".format(a, b))
if __name__ == '__main__':
send = MyTypeSignal()
slot = MySlot()
send.sendmsg.connect(slot.get)
send.sendmsg1.connect(slot.get1)
send.run() # 发送信号到slot.get
send.run1() # 发送信号到slot.get1
# send.sendmsg.disconncet(slot.get) # 断开连接