[Interest] Why does QML prefer 'count' over '.length'?
jpnurmi at qt.io
Tue Jul 26 22:41:29 CEST 2016
On Tuesday, July 26, 2016 22:04,Jason H <jhihn at gmx.com> wrote:
> JS uses length on arrays and strings. Anytime you have an array (be it a list, etc) the number of items is denoted as .length
And in QML you have .length where you'd expect to have it, in JS arrays and strings.
> It makes no sense to have Qt use count in similar situations.
Arrays and strings are not exactly similar situations to item views and item models. :)
> As Thiago mentioned length, size and count are all analogous in the C++ API, so I don't know how/why they are ambiguous.
The C++ API of the Qt containers. Not item views nor item models. Two entirely different worlds. The length or size of an array is clear, but the length or size of a list view is likely to get associated to the UI element's visual geometry.
> I write quite a bit of JS code (server and mobile) and it seems rather arbitrary to continue to use count. >
> Specific places:
> All models. DelegateModel, DelegateModelGroup, ListModel, etc.
It's not that arbitrary. "Count" is used all over in item views and item models, in C++ and in QML.
More information about the Interest