1 回答
TA贡献1846条经验 获得超7个赞
除了重载信号支持的类型之外,您还必须使连接指向连接中的签名:
import sys
from PyQt5 import QtCore
class Controller(QtCore.QObject):
trigger = QtCore.pyqtSignal([str], [str, str])
def __init__(self):
super(Controller, self).__init__()
self.trigger[str].connect(self.function)
self.trigger[str, str].connect(self.function)
@QtCore.pyqtSlot(str)
@QtCore.pyqtSlot(str, str)
def function(self, argument, optional_argument=''):
print(argument, optional_argument)
def main():
app = QtCore.QCoreApplication(sys.argv)
c = Controller()
c.trigger[str].emit('Hello')
c.trigger[str, str].emit('Hello', 'World')
QtCore.QTimer.singleShot(100, QtCore.QCoreApplication.quit)
sys.exit(app.exec_())
if __name__ == "__main__":
main()
添加回答
举报