[Interest] ListView/ListModel optimization

Kevin Mcintyre kebin70 at gmail.com
Tue May 3 19:32:01 CEST 2016


Given code like below where JSON data is used to populate a ListModel
- I run into loading issues on mobile when the number of objects
returned is greater than a couple thousand.s


Once the item is rendered it performs as expected, but the time to
ready is often beyond user acceptance.


Any suggestions greatly appreciated.

 import QtQuick 2.5

import QtQuick.Window 2.2


Window {

    visible: true


    Repeater {

        model: ['url1','url2','url3']

        ListView {

            delegate: Image {

                source: src

            }

            model: ListModel {

                Component.onCompleted {

                    var xhr = new XMLHttpRequest();

                    xhr.onreadystatechange = (function(data) {

                        return function() {

                            if ( data.readyState == 4 ) {

                                console.log('answered:', url)

                                try {

                                    var js = eval('new Object(' +
data.responseText + ')')

                                    for (var x = 0; x < js.length;x++) {

                                        append({'src': js[x].src})

                                    }

                                } catch (err) {

                                    console.log('error:', modelData, err);

                                }

                            }

                        }

                    })(xhr);

                    console.log('request:', url)

                    xhr.open('GET', modelData, true);

                    xhr.setRequestHeader('accept','application/json')

                    xhr.send('');

                }

            }

        }

    }

}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20160503/49ce6616/attachment.html>


More information about the Interest mailing list