当使用自动连接连接插槽,而QListView :: currentChanged(电流,以前的)信号,我得到:解决的:Qt 4.8.4:不能插槽连接而QListView :: currentChanged()信号
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)
编辑2 (解决方案):
好吧,我正在检查文档的第十次,只是意识到QListView :: currentChanged(...)实际上是一个插槽而不是一个信号。我只是用我需要的信号创建了QListView的自定义子类,并使currentChanged发出该信号。
感谢您的帮助!
我不知道PySide _at all_,但你没有装饰'onmodelosView_currentChanged(..)'方法作为一个插槽,而不是信号? – cmannett85 2013-02-13 15:41:18
它应该是一个插槽。你为什么认为这应该是一个信号? – 2013-02-14 11:15:25
“没有匹配的信号on_modelosView_currentChanged(QModelIndex,QModelIndex)” – cmannett85 2013-02-14 11:48:46