Using a QML model from a QDeclarativeItem subclass
Hi! I’m creating a QDeclarativeItem subclass:
- class MyGraphic : public QDeclarativeItem
- {
- Q_OBJECT
- Q_PROPERTY(????? model READ model SET model)
- public:
- MyGraphic(QDeclarativeItem *parent = 0);
- ...
- };
I would like to use it in QML like this:
- Rectangle {
- ListModel {
- id: mymodel
- ListElement { type: "Oranges"; amount: 35 }
- ListElement { type: "Apples"; amount: 27 }
- ListElement { type: "Peaches"; amount: 12 }
- }
- MyGraphic {
- width: 300; height: 200
- model: mymodel
- }
- }
There are plenty of examples on how to make a C++ model available in the QML world but I have found nothing on how to access a QML model from C++.
How can I access mymodel from MyGraphic (the C++ class)? Should I use QAbstractItemModel* directly in the Q_PROPERTY?
I mean something like:
- {
- int amount = model->data(...);
- // paint a graphic using the "type" and "amount" variables
- }
4 replies
Sounds like the same question as this [developer.qt.nokia.com].
Short answer: AFAIK, this is not yet possible*, as the QML model API is private API.
*) in a supported way.
You must log in to post a reply. Not a member yet? Register here!



