Discussion:
setData from QML on a qabstractitemmodel
qt next
15 years ago
Permalink
Hi,

I have a c++ qabstractitemmodel. I can display this model in qml but I don't
how to edit data from qml delegate. Is it possible to do this ? I have tryed
model.setData, model.property= without success.
I hopes it's possible
m***@public.gmane.org
15 years ago
Permalink
Hi,

Unfortunately there is no automatic way to do this at the moment (http://bugreports.qt.nokia.com/browse/QTBUG-7932 is the issue that tracks this). One solution at this point would be to add a custom slot (or Q_INVOKABLE) to your model that can be called from QML -- this is how the ListModel element handles it. For example, something like

void setModelProperty(int index, QString property, QVariant value);

could be called from your delegate:

Item {
id: delegate
...
TextInput { id: label; ... }
MouseArea {
anchors.fill: parent
// assuming your model has been exposed to QML as "myModel", and has a role name "name" which takes a string
onClicked: myModel.setModelProperty(index, "name", label.text)
}
}

Regards,
Michael
Hi,
I have a c++ qabstractitemmodel. I can display this model in qml but I don't how to edit data from qml delegate. Is it possible to do this ? I have tryed model.setData, model.property= without success.
I hopes it's possible
<ATT00001..txt>
Loading...