51 /* |
51 /* |
52 This example illustrates exposing a QList<QObject*> as a |
52 This example illustrates exposing a QList<QObject*> as a |
53 model in QML |
53 model in QML |
54 */ |
54 */ |
55 |
55 |
|
56 //![0] |
56 int main(int argc, char ** argv) |
57 int main(int argc, char ** argv) |
57 { |
58 { |
58 QApplication app(argc, argv); |
59 QApplication app(argc, argv); |
59 |
|
60 QDeclarativeView view; |
|
61 |
60 |
62 QList<QObject*> dataList; |
61 QList<QObject*> dataList; |
63 dataList.append(new DataObject("Item 1", "red")); |
62 dataList.append(new DataObject("Item 1", "red")); |
64 dataList.append(new DataObject("Item 2", "green")); |
63 dataList.append(new DataObject("Item 2", "green")); |
65 dataList.append(new DataObject("Item 3", "blue")); |
64 dataList.append(new DataObject("Item 3", "blue")); |
66 dataList.append(new DataObject("Item 4", "yellow")); |
65 dataList.append(new DataObject("Item 4", "yellow")); |
67 |
66 |
|
67 QDeclarativeView view; |
68 QDeclarativeContext *ctxt = view.rootContext(); |
68 QDeclarativeContext *ctxt = view.rootContext(); |
69 ctxt->setContextProperty("myModel", QVariant::fromValue(dataList)); |
69 ctxt->setContextProperty("myModel", QVariant::fromValue(dataList)); |
|
70 //![0] |
70 |
71 |
71 view.setSource(QUrl("qrc:view.qml")); |
72 view.setSource(QUrl("qrc:view.qml")); |
72 view.show(); |
73 view.show(); |
73 |
74 |
74 return app.exec(); |
75 return app.exec(); |