我最近从 pyside
迁移到 pyqt5
,但出现了问题。我在网上查了一下,显然,使用 pyqt4 并迁移到 pyqt5 的人已经发生过这种情况。但是,它并没有真正帮助...我尝试在 Qobject
之后添加 pyqtSignal
但它仍然无法正常工作。请帮忙。
这些是我的代码行:
QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL("accepted()"),Dialog.accept)
QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL("rejected()"), Dialog.reject)
这是我运行它时出现的内容:
AttributeError: type object 'QObject' has no attribute 'connect'
最佳答案
connect(slot[, type=PyQt5.QtCore.Qt.AutoConnection[, no_receiver_check=False]])
Connect a signal to a slot. An exception will be raised if the connection failed. Parameters:
slot
– the slot to connect to, either a Python callable or another bound signal.type
– the type of the connection to make.no_receiver_check
– suppress the check that the underlying C++ receiver instance still exists and deliver the signal anyway.
举个例子:
self.buttonBox.accepted.connect(Dialog.accept) # pyqt5
QtCore.QObject.connect(self.buttonBox.rejected, Dialog.reject) # pyqt4
作为旁注,“Dialog”听起来像一个类,您可能想要连接到一个实例,否则请考虑使用小写前字母命名您的实例...
关于python-3.x - pyqt5中的连接功能不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49315647/