[Solved] Loading a ListModel dynamically
I have a ListModel populated from a local file (via XMLHttpRequest) during onCompleted. The list is loaded but too late for it to show in the ListView. i.e. when I add logging I can see the items are loaded after the ListView has been onCompleted.
How can I either force the population earlier or force the model to sync. I need something like model.sync() but this is only available from .js and not .qml.
Have a look at the Twitter example in the SDK which uses the same method as you.
For syncing, you can just re-evaluate model as whatever you have set it to.
For example, if you have:
in your ListView, then to sync you do:
@model = xmlModel@
[quote author="SimonJudge" date="1292425962"]I have a ListModel populated from a local file (via XMLHttpRequest[/quote]
By the way, why are you using ListModel instead of XmlListModel (see Twitter example)?
"XmlListModel":http://doc.qt.nokia.com/latest/qml-xmllistmodel.html has a few advantages such as .reload() to gather the model from server again and .status() to check when data is ready.
Thanks for the tips. I am not using XmlListModel because I am loading JSON (and from multiple JSON files to create the model)
I have assigned the model after a small delay (Timer) as per the Twitter sample that does something similar for "Workaround for bug 260266". Logging shows the items are loaded after the delay but the assignment doesn't re-sync the ListView. I am sure there must be a simple way to fix this that works.
Ok, I have this working now thanks. The assignment wasn't working because I had a wrapper (item) around the ListView that wasn't passing on the assignment. I have also improved the mechanism by having a signal when the data has loaded which then causes the assignment in the view.