将操作连接到方法时出现pyqt5移植错误:AttributeError:type object' QObject'没有属性' connect'

时间:2017-05-10 13:27:12

标签: python-3.5 pyqt5

我知道这是一个典型的pyqt4到pyqt5移植问题,但到目前为止,现有的问题并没有帮助我找到解决当前问题的方法:我可以推动吗?

以下是生成以下错误的类

AttributeError: type object 'QObject' has no attribute 'connect'

班级

import logging
import sys
import time

from PyQt5 import QtCore, QtGui, QtWidgets

from gui.gui import Ui_MainWindow

from lib import bcinetwork
from lib import bcixml

triggered = QtCore.pyqtSignal()
NORMAL_COLOR = QtCore.Qt.black
MODIFIED_COLOR = QtCore.Qt.gray

#class BciGui(QtGui.QMainWindow, Ui_MainWindow):
class BciGui(QtWidgets.QMainWindow, Ui_MainWindow):

    def __init__(self, protocol='bcixml'):
        #QtGui.QMainWindow.__init__(self)
        QtWidgets.QMainWindow.__init__(self)

        self.setupUi(self)
        self.protocol = protocol

        self.model = TableModel(self)
        self.proxymodel = QtCore.QSortFilterProxyModel(self)
        self.proxymodel.setSourceModel(self.model)
        self.proxymodel.setFilterKeyColumn(- 1)
        self.proxymodel.setDynamicSortFilter(True)
        self.tableView.setModel(self.proxymodel)
        self.tableView.verticalHeader().setVisible(False)
        self.tableView.horizontalHeader().setSectionResizeMode(1, QtWidgets.QHeaderView.Stretch)
        self.tableView.sortByColumn(0, QtCore.Qt.AscendingOrder)
        self.tableView.setSortingEnabled(True)




    self.toolButton_clearFilter.setDefaultAction(self.actionClearFilter)

    self.comboBox_feedback = QtWidgets.QComboBox(self.toolBar)

    self.comboBox_feedback.setSizePolicy(QtWidgets.QSizePolicy.Expanding,
                                         QtWidgets.QSizePolicy.Preferred)
    self.toolBar.insertWidget(self.actionSendInit, self.comboBox_feedback)



        # connect actions to methods
        #QtCore.QObject.connect(self.actionOpen, QtCore.SIGNAL("triggered()"), self.clicked)

        QtCore.QObject.connect(self.actionChangeFeedbackController, QtCore.SIGNAL("triggered()"), self.changeFeedbackController)

        QtCore.QObject.connect(self.actionClearFilter, QtCore.SIGNAL("triggered()"), self.clearFilter)
        QtCore.QObject.connect(self.actionOpen, QtCore.SIGNAL("triggered()"), self.open)
        QtCore.QObject.connect(self.actionPause, QtCore.SIGNAL("triggered()"), self.pause)
        QtCore.QObject.connect(self.actionPlay, QtCore.SIGNAL("triggered()"), self.play)
        QtCore.QObject.connect(self.actionQuit, QtCore.SIGNAL("triggered()"), self.quit)
        QtCore.QObject.connect(self.actionStop, QtCore.SIGNAL("triggered()"), self.stop)
        QtCore.QObject.connect(self.actionSave, QtCore.SIGNAL("triggered()"), self.save)
        QtCore.QObject.connect(self.actionSaveAs, QtCore.SIGNAL("triggered()"), self.saveas)
        QtCore.QObject.connect(self.actionSendModified, QtCore.SIGNAL("triggered()"), self.sendModified)
        QtCore.QObject.connect(self.actionSendAll, QtCore.SIGNAL("triggered()"), self.sendAll)
        QtCore.QObject.connect(self.actionSendInit, QtCore.SIGNAL("triggered()"), self.sendinit)
        QtCore.QObject.connect(self.actionGet, QtCore.SIGNAL("triggered()"), self.get)

        QtCore.QObject.connect(self.lineEdit, QtCore.SIGNAL("textChanged(const QString&)"), self.filter)
        QtCore.QObject.connect(self.model, QtCore.SIGNAL("dataChanged(const QModelIndex&, const QModelIndex&)"), self.dataChanged)

        self.feedbacks = []

        self.setFeedbackController(bcinetwork.LOCALHOST, bcinetwork.FC_PORT)

通常将操作连接到此处的方法

时会出现问题
        QtCore.QObject.connect(self.actionChangeFeedbackController, QtCore.SIGNAL("triggered()"), self.changeFeedbackController)

这让我得到了提及的错误

AttributeError: type object 'QObject' has no attribute 'connect'

我理解代码的这一部分是典型的Pyqt4问题,它在Pyqt5中不再起作用。所以我看到了针对特定小部件的新信号的许多解释,但我没有看到一般的动作的解决方案。有人能给我一个解释吗?

THKS

1 个答案:

答案 0 :(得分:0)

好吧我认为我通过以下方式实现了它:

#QtCore.QObject.connect(self.actionChangeFeedbackController, QtCore.SIGNAL("triggered()"), self.changeFeedbackController)
 self.actionChangeFeedbackController.triggered.connect(self.changeFeedbackController)