python - Solved: Qt 4.8.4: Cannot connect slot to QListView::currentChanged() signal -
when connecting slot qlistview::currentchanged(current, previous) signal using auto connection get:
qmetaobject::connectslotsbyname: no matching signal on_modelosview_currentchanged(qmodelindex,qmodelindex)
not using auto connection get:
attributeerror: 'builtin_function_or_method' object has no attribute 'connect'
i'm using pyside , code follows:
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())
where: modelosmodel subclass of qtabstractlistmodel , modelosview qlistview widget.
my goal utilize signal update mapper index user can select item wants in qlistview , edit in qplaintextedit using mapper.
edit: clear confusion code originated first error:
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())
i using auto connect feature got error:
qmetaobject::connectslotsbyname: no matching signal on_modelosview_currentchanged(qmodelindex,qmodelindex)
edit 2 (solution):
ok, checking docs 10th time , realized qlistview::currentchanged(...) slot , not signal. created custom subclass of qlistview signal needed , made currentchanged emit signal instead.
thanks help!
it's not coming connect()
statement, setupui()
.
by default, setupui()
adds phone call qmetaobject::connectsignalsbyname(widget)
, widget
argument passed setupui()
(in case: self
).
that call, in turn, slots of self
name resembling
on_childobjectname_signalname
and seek figure out if self
has kid object named childobjectname
(in sense of qobject::objectname()
; if so, it seek connect signalname
slot. don't that.
long story short: don't name slots using on_child_signal
pattern unless plan utilize connectsignalsbyname
.
(on other hand, it's quite convenient widgets created using designer: since designer give kid widgets name, can hook signals using feature, create slot called on_child_signal
, magically work.)
python qt signals pyside qlistview
No comments:
Post a Comment