PyQT5之自定义信号

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)   # 断开连接

posted @ 2024-06-08 05:34  星空28  阅读(7)  评论(0编辑  收藏  举报