[Interest] QML ListModel woes

Jason H jhihn at gmx.com
Tue Mar 31 18:53:27 CEST 2015


Given that I work with almost entirely JSON data, I find myself now lamenting the QML ListModel. Even The JSONListModel that can be found online isn't great. It all suffers from the same flaws as ListModel. My major complaint is that models, don't use a length  property and instead use count, that you have specialized access with count, get, set, append and setProperty. Why can't we use the standard JSON manipulation tools and just set a ListModel to an array of a JSON object.  Also some basic filter function would go a long way to reducing the number of marshaling functions I need to write.

Ideally, I'd like the Following:
JSONModel {
obj: {name: 'Test model', data: [{a:1, b:2],  [{a:3, b:4]}}
listProperty: 'data'
filter: function (item) { return item.a >2 } // if true, it's in the model default function is {return true}
}

In this way, I wouldn't have to write all these function to marshall data into and out of ListModels. I realize there might be an issue with raw JS access to the object itself (i.e. model.obj.data[0].a=4, however I'd much rather call model.sync() on those changes rather than write all these functions that just do appends(). Another way to handle the update issue is to use Observable pattern, like in Knockout and Angular.


And lastly, could we get the standard accesses aliased? At least: append->push count->length get->[] 




More information about the Interest mailing list