Important: Please read the Qt Code of Conduct -

ListModel sync() Function Throwing Out-Of-Range Errors

  • Hello all,

    In my QML app, I have a WorkerScript that I'm using to fill a ListModel with data from a database or file. This ListModel then provides the data for a Repeater to display it in a Column. As far as I can tell, it is filling properly, but I'm getting tons of errors saying that I'm calling set() on the ListModel when it is synced at the end of the WorkerScript. I am able to get rid of the error messages by syncing after every append() that I call in the script, but that is uselessly inefficient.

    Again, it seems that the data is being loaded properly, but the messages still keep popping up in the console. Perhaps it is a bug.

    If anyone can see what I could be doing wrong, help would be appreciated.


  • Hi @larkei15
    I don't think using a Repeater for dynamically changing models is the best approach.

    From the Cadaques book:

    For static models, a Repeater can be used as the view. It is easy to combine it with a positioner such as Row, Column, Grid or Flow to build user interface parts. For dynamic or large data models, a view such as ListView or GridView are more appropriate. These create delegate instances on the fly as they are needed, reducing the number of elements live in the scene at once.

    And from the QML doc:

    Considerations when using Repeater
    The Repeater type creates all of its delegate items when the repeater is first created. This can be inefficient if there are a large number of delegate items and not all of the items are required to be visible at the same time. If this is the case, consider using other view types like ListView (which only creates delegate items when they are scrolled into view) or use the Dynamic Object Creation methods to create items as they are required.

    I wager your syncing problems are due to that...

    Is there any reason why you are choosing the Column+ Repeater approach over the ListView approach?