Reputation: 1604
I have a XmlListModel that fetches data from a webserver, which works great.
However, I want to use that in a CLComboBox (from the Colibri library).
If I set the parameter ListModel to my XmlListModel I get:
Non-existent attached object
ListModel:xmlModel13
But it does exists; since a ListView-object can use the very same model.
It seems to me that the CLComboBox only accepts a ListModel, so is there any way to transform a XmlListModel to a ListModel easily?
Upvotes: 1
Views: 2064
Reputation: 3631
You cannot cast QDeclarativeXmlListModel
to QDeclarativeListModel
because they both direct descendants of QListModelInterface
.
In my opinion Colibri should use a QObject
(variant
property) instead of QDeclarativeListModel
. And listen for standard item-based-model signals e.g. I believe it could be fixed with some effort.
If you not willing to contribute to Colibri, I think @sabbour's answer is best option. Consider simple example:
XmlListModel {
id: xmlModel
source: "http://forumcinemas.lv/rus/xml/Events/"
query: "/Events/Event"
XmlRole { name: "label"; query: "Title/string()" }
XmlRole { name: "value"; query: "ID/number()"; isKey: true }
onStatusChanged: {
if (status == XmlListModel.Ready) {
for (var i=0; i<count; i++) {
var item = get(i)
list_model.append({label: item.label,
value: item.value,
selected: false})
}
// CLComboBox doesnt seem to listen for model updates
combo_box.items = list_model
}
}
}
ListModel {
id: list_model
}
CLComboBox {
id: combo_box
// ...
}
Upvotes: 4
Reputation: 5009
You can populate the ListModel inside the CLComboBox using a loop.
Upvotes: 1