当使用自动连接将插槽连接到 QListView::currentChanged(current, previous) 信号时,我得到:
QMetaObject::connectSlotsByName: No matching signal for on_modelosView_currentChanged(QModelIndex,QModelIndex)
不使用自动连接我得到:
AttributeError: 'builtin_function_or_method' object has no attribute 'connect'
我正在使用 PySide,我的代码如下:
class Modelos(QtGui.QDialog):
def __init__(self, parent):
QtGui.QDialog.__init__(self, parent)
self.ui = Ui_Dialog()
self.ui.setupUi(self)
# Inicializa o modelo
self.model = ModelosModel(self)
self.ui.modelosView.setModel(self.model)
# Inicializa o mapper
self.mapper = QtGui.QDataWidgetMapper(self)
self.mapper.setModel(self.model)
self.mapper.addMapping(self.ui.modelosEdit, 0)
self.mapper.toFirst()
self.ui.modelosView.currentChanged.connect(self.onmodelosView_currentChanged)
@QtCore.Slot(QtCore.QModelIndex, QtCore.QModelIndex)
def onmodelosView_currentChanged(self, current, previous):
self.mapper.setCurrentIndex(current.row())
其中:ModelosModel 是 QtAbstractListModel 的子类,modelosView 是 QListView 小部件。
我的目标是使用此信号更新映射器索引,以便用户可以在 QListView 中选择他想要的项目并使用映射器在 QPlainTextEdit 中对其进行编辑。
编辑:为了消除混淆,这是产生第一个错误的代码:
class Modelos(QtGui.QDialog):
def __init__(self, parent):
QtGui.QDialog.__init__(self, parent)
self.ui = Ui_Dialog()
self.ui.setupUi(self)
# Inicializa o modelo
self.model = ModelosModel(self)
self.ui.modelosView.setModel(self.model)
# Inicializa o mapper
self.mapper = QtGui.QDataWidgetMapper(self)
self.mapper.setModel(self.model)
self.mapper.addMapping(self.ui.modelosEdit, 0)
self.mapper.toFirst()
@QtCore.Slot(QtCore.QModelIndex, QtCore.QModelIndex)
def on_modelosView_currentChanged(self, current, previous):
self.mapper.setCurrentIndex(current.row())
我显然在使用自动连接功能,但出现错误:
QMetaObject::connectSlotsByName: No matching signal for on_modelosView_currentChanged(QModelIndex,QModelIndex)