[Qt-qml] setData from QML on a qabstractitemmodel

michael.brasser at nokia.com michael.brasser at nokia.com
Mon Sep 27 02:55:38 CEST 2010


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

On 26/09/2010, at 2:03 AM, ext qt next wrote:

> 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>





More information about the Qt-qml mailing list