Hi! I'm creating a QDeclarativeItem subclass:

Qt Code:
  1. class MyGraphic : public QDeclarativeItem
  2. {
  3. Q_OBJECT
  4. Q_PROPERTY(????? model READ model SET model)
  5.  
  6. public:
  7. MyGraphic(QDeclarativeItem *parent = 0);
  8. void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
  9. ...
  10. };
To copy to clipboard, switch view to plain text mode 

I would like to use it in QML like this:

Qt Code:
  1. Rectangle {
  2. ListModel {
  3. id: mymodel
  4. ListElement { type: "Oranges"; amount: 35 }
  5. ListElement { type: "Apples"; amount: 27 }
  6. ListElement { type: "Peaches"; amount: 12 }
  7. }
  8.  
  9. MyGraphic {
  10. width: 300; height: 200
  11. model: mymodel
  12. }
  13. }
To copy to clipboard, switch view to plain text mode 

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:

Qt Code:
  1. void MyGraphic::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
  2. {
  3. QString type = model->data(...); // model would be "mymodel" from QML
  4. int amount = model->data(...);
  5. // paint a graphic using the "type" and "amount" variables
  6. }
To copy to clipboard, switch view to plain text mode