[Qt-qml] how to expose nested ListModel from C++ to QML?
Wei, Xiaohai
wistoch at gmail.com
Thu Dec 9 11:13:01 CET 2010
I need to use nested ListView in QML. In each item of the outer ListView,
named by A, it will contain another ListView B.
I can easily expose the DataModel for A from C++, but how can I expose the
list of DataModel for each B?
I have a C++ class derived from QAbstractListModel, and expose an instance
mySuperListModelA to QML for the ListView A by setContextProperty.
In the instance of this class, I have a list of another QAbstractListModel
subclass instance, but how can I expose them to QML for use by B?
I used an INVOKABLE method in class A which will return a
QAbstractListModel, and use it as the model of the inner ListView, but it
doesn't work.
Thanks
James
import Qt 4.7
Item {
id: container
Rectangle {
id: menu
width: 400
height: 600
color: "black"
opacity: 0.75
radius: 0
clip: true
Component {
id: outerDelegate
Column{
Text {
text: "Site Title : " + title
}
Component {
id: innerDelegate
Column {
Text { text: " Tab Title: " + tabtitle }
}
}
Repeater {
model: mySuperListModelA.subListModelAt(index) // return sub
QAbstractListModel via INVOKABLE method of mySuperListModelA
delegate: innerDelegate
}
} // Column
} // Component
ListView {
id: outerlistview
anchors.fill: parent
delegate: outerDelegate
model: mySuperListModelA
opacity: 1
} // ListView
} // Rectangle
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt.nokia.com/pipermail/qt-qml/attachments/20101209/e8de77ba/attachment.html
More information about the Qt-qml
mailing list