[Qt-qml] Exposing data model from C++
ari.koivisto at nokia.com
ari.koivisto at nokia.com
Mon Nov 22 11:02:34 CET 2010
Hi,
I've been trying to move my QML/JS program into a hybrid QML/C++ and I've run into some implementation issues.
On the QML + JS side I had a simple listmodel along the lines:
ListModel {
ListElement { start: "12:30"; ... ; legs: [ { type: "train"; id: "IC82"; ... }, ... ] }
ListElement { start: "13:00"; ... ; legs: [ { type: "train"; id: "S62"; ... }, ... ] }
}
I can then visualize this using ListView and having a Repeater to go through the elements "legs" data. Resulting in something like this:
| 1. Start: 12:30 ... | IC82 | ... |
| 2. Start: 13:00 ... | S62 | ... |
Now I'm not sure how to achieve the same functionality from C++ side. I have a data model representing the data as in the pure QML example. It is an QAbstractListModel inherited model that exposes named roles for "start" e.g. elements as documented in:
http://docs.huihoo.com/qt/4.7/qdeclarativemodels.html#qabstractitemmodel
The problem comes with the C++ equivalent of the "legs" element, which is an another QList in the data model. How can that be exposed so that I can again use Repeater to achieve the same visualization like in the pure QML data model?
Documentation suggests using QAbstractItemModel and VisualDataModel, but that seems a bit overly complex? E.g. Could QAbstractListModel::data return an another QAbstractListModel that the Repeater could use directly?
Thanks,
Ari
More information about the Qt-qml
mailing list