[Qt-qml] Model view example showing editing capability
bea.lam at nokia.com
bea.lam at nokia.com
Mon Jan 17 08:04:38 CET 2011
You can find an example of using QAbstractListModel with QML under examples/declarative/modelviews/abstractitemmodel. The example is also online at http://doc.qt.nokia.com/4.7-snapshot/declarative-modelviews-abstractitemmodel.html.
The example doesn't modify the model from QML, but you could for example add a method to the model class like this:
Q_INVOKABLE void updateModel(int index, const QVariant &value);
and then you can call this from QML to modify the model data.
The example shows some of the signals that needs to be emitted from a Qt model in order to update the view (e.g. QAbstractItemModel::beginInsertRows() ). If you are simply changing the data in an existing row, then emit dataChanged(). See http://doc.qt.nokia.com/4.7-snapshot/model-view-programming.html#model-subclassing-reference.
regards,
Bea
On 15/01/2011, at 6:38 PM, ext Pelle Johnsen wrote:
> Hi,
>
> I can recommend subclassing QAbstractListModel (http://doc.trolltech.com/4.7/qabstractlistmodel.html). You can use a normal QList, but it only has a single change signal, so if e.g. you insert an item then QML thinks the whole list has changed, which can cause performance problems. The whole Qt model/view classes are rather complex (compared to QList), but in my experience it's worth the effort to use it.
>
> -pjoe
>
> On Fri, Jan 14, 2011 at 6:26 PM, Jamil Naja <jamil.m.naja at gmail.com> wrote:
> Hi guys,
> As the title suggests, I am looking for an example with a C++ model and QML view where the QML view (or other QML elements within the QML code) doing modification on the c++ model data.
>
> Any suggestions ?
>
> Thanks
> Jamil
>
> _______________________________________________
> Qt-qml mailing list
> Qt-qml at qt.nokia.com
> http://lists.qt.nokia.com/mailman/listinfo/qt-qml
>
>
> <ATT00001..txt>
More information about the Qt-qml
mailing list