MainWindow 对象没有属性“connect”

2024-04-16

我想知道是否有人可以帮助我解决有关 PyQt5 中插槽连接的问题。下面的代码片段将告诉你我的问题是什么。

class MainWindow(QMainWindow):
    def __init__(self):
        super(MainWindow, self).__init__()
        path = os.path.join(os.path.dirname(__file__), 'GUI/Main_GUI.ui')
        self.gui = loadUi(path)

        self.gui.button_1.clicked.connect(self.run.this)

    def _connect_my_slots(self, origin):
        self.connect(origin, SIGNAL('completed'), self._show_results)
        self.connect(origin, SIGNAL('error'), self._show_error)

    def run_this(self):
        myThread = LongRunningThing()
        self._connect_my_slots(self.myThread) # THIS IS THE PART THAT CAUSES ERROR

正如你所看到的MainWindow对象是我的 UI 文件(来自 QtDesigner 5),一旦我调用_connect_my_slots函数会抛出错误:

AttributEerror:“MainWindow”对象没有属性“connect”


您正在使用旧式信号和槽,PyQt5 不再支持它们。

旧风格:

self.connect(origin, SIGNAL('completed'), self._show_results)

现在应该用新的风格编写:

origin.completed.connect(self._show_results)

有关更多详细信息,请参阅有关的文档新型信号和时隙支持 http://pyqt.sourceforge.net/Docs/PyQt4/new_style_signals_slots.html.

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

MainWindow 对象没有属性“connect” 的相关文章

随机推荐