[Interest] Best model type for shared data between C++ and QML, as well as insertion and removal on both sides.

Ian Monroe ian at monroe.nu
Fri Nov 21 02:13:39 CET 2014


On Thu, Nov 20, 2014 at 2:40 PM, Nuno Santos <nunosantos at imaginando.pt>
wrote:

> I have subclassed QAbstractListModel and i’m already able to have the
> model listed in a list view.
>
> What I can’t find is how I programmatically add items to the model from
> the QML side and which methods I need to reimplement in my model class.
>
> The qml-object-model you have sent me is probably old because there aren’t
> the same methods on the documentation for Qt 5.3
>
> Suggestions?
>

There's nothing really magical about QAbstractItemModel in QML. They don't
turn into ListModel's, they are still plain QAbstractItemModel that have
the methods in C++. Their only superpower is that QML ListView can use it
as a model.

Just add whatever methods make sense to QAbstractItemModel to insert and
edit the data and call them from QML.

Ian
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20141120/8abee773/attachment.html>


More information about the Interest mailing list