[SailfishDevel] How to convert Xml list model into QML list model?
Jollailija Developer
jollailija at gmail.com
Sat Dec 12 06:50:59 UTC 2015
Okay, I think I found the cause. The function needs to be somewhere where
it can see both of the list models. The question is "where is that?"
I wrote this into the main QML:
Component{QmlListModel{id:qmlListModel}}
Component{StationsModel{id:stationsModel}}
function fillList() {
var i = 0
for (var r = 0; r < 10; r++) {
qmlListModel.append({"title": stationsModel.get(i).title})
// <- line 92
i ++
console.log(i)
}
}
Timer {
interval: 5000
repeat: false
onTriggered: {fillList(); console.log("fill")}
running: true
}
Quess what the console says?
[W] unknown:92 -
file:///usr/share/harbour-nettiradio/qml/harbour-nettiradio.qml:92:
ReferenceError: qmlListModel is not defined
Not defined? It's right there!
I have no idea what I'm doing.
(want to take a look? source at https://github.com/jollailija/nettiradio )
Cheers,
Reference error: jollailija is not defined
2015-12-12 8:02 GMT+02:00 Jollailija Developer <jollailija at gmail.com>:
> I switched onCompleted to this:
> Component.onCompleted: qmlListModel.append({"title": stationsModel
> .get(3).title})
> There should be over 70 items on this list. I think I will need to try to
> do the conversion at some other place, maybe it can't see it.
>
> 2015-12-11 21:50 GMT+02:00 Alexander Ladygin <fake.ae at gmail.com>:
>
>> seems like index out of bounds
>>
>> stationsModel items count is smaller than lib.stationCount
>>
>>
>>
>> On Fri, Dec 11, 2015 at 10:28 PM, Jollailija Developer <
>> jollailija at gmail.com> wrote:
>>
>>> Hi,
>>>
>>> I am using Alpha Menu (People app style sorting) in my app. However it
>>> only supports QML ListModel as it's dataSource. I tried doing this:
>>>
>>> StationsModel {id:stationsModel}
>>>
>>>
>>> ListModel {
>>>
>>> id: qmlListModel
>>>
>>> }
>>>
>>> Component.onCompleted: {console.log(lib.stationCount);fillList()}
>>>
>>>
>>> function fillList() {
>>>
>>> var i = 0
>>>
>>> for (var r = 0; r < lib.stationCount; r++) {
>>>
>>> qmlListModel.append({"title": stationsModel.get(i).title}) //< line 52
>>>
>>> i ++
>>>
>>> console.log(i)
>>>
>>> }
>>>
>>> }
>>>
>>>
>>> Well, it isn't working. What's wrong with it? Here's the output:
>>>
>>> [W] unknown:52 - file:///usr/share/harbour-nettiradio/qml/Pages/StationGridView.qml:52: TypeError: Cannot read property 'title' of undefined
>>>
>>>
>>> "Good night to you, dear devs!" wishes
>>> jollailija
>>>
>>>
>>> _______________________________________________
>>> SailfishOS.org Devel mailing list
>>> To unsubscribe, please send a mail to
>>> devel-unsubscribe at lists.sailfishos.org
>>>
>>
>>
>> _______________________________________________
>> SailfishOS.org Devel mailing list
>> To unsubscribe, please send a mail to
>> devel-unsubscribe at lists.sailfishos.org
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.sailfishos.org/pipermail/devel/attachments/20151212/2fed6ceb/attachment.html>
More information about the Devel
mailing list