python-3.x - pyqt5中的连接功能不起作用

标签 python-3.x pyqt pyside

我最近从 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'

最佳答案

from the docs :

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/

相关文章:

python - PDF 与 QWebView : missing refresh/repaint after loading

python - 薛定谔变量 : the __class__ cell magically appears if you're checking for its presence?

python - bool 数组到整数

python - 正确地将变量传递给函数

python - 无法从 PyQt4 导入 QtCore 或 QtGui

python - PyQt:Dialog 的最小化窗口按钮在 OSX 中丢失

python - 对象超出范围并在 PySide/PyQt 中被垃圾收集

python - 在 python 单元测试运行时重置全局变量

python - PyQt 从 excel 填充 QTableWidget

python - 如何在 PySide 中获取 QProcess 运行的命令的输出?