[Interest] Why does QML prefer 'count' over '.length'?

Michael Brasser michael.brasser at live.com
Thu Jul 28 18:39:38 CEST 2016


While I don't have anything to add on the relative merits of length vs count , I do understand the general frustration.

With large QML projects there can be a large number of "data collections". Those might be implemented in terms of ListModel, a custom QAbstractListModel-derived class, QStringList, QObjectList, or a JS array. These are interchangable in some aspects (e.g. all can be assigned to the model property of a view), but not all, and it can be an annoyance in those cases where it is not. For me I have personally had to "think more" when it comes to:

* getting the number of items in my collection
* how the data is made accessible to the delegate (model vs context properties vs modelData)

As the above differ based on the type of data collection I am working with. I'd welcome anything Qt could provide to make those things easier.



From: Interest <interest-bounces+michael.brasser=live.com at qt-project.org> on behalf of J-P Nurmi <jpnurmi at qt.io>
Sent: Thursday, July 28, 2016 10:05:59 AM
To: interest at qt-project.org
Subject: Re: [Interest] Why does QML prefer 'count' over '.length'?

On Thursday, July 28, 2016 15:46, Jason H <jhihn at gmx.com> wrote:
> Look, I know JS was invented in 10 days back in 1995. There's no shortage of things to complain about. But
> 'length' was chosen, and it is the number of items. I would agree with you that length is not as good as 'count', but
> the language is the language. Qt should move to be in compliance wit the language because JS was using it first,
> then Qt moved into JS. Unless you want to convince JS they should add count to everything as well. And I assure
> you there is more lines of JS using length than all lines of QML put together.
> Consider the absurdity of the reverse:
> Why don't we ditch .length in QML and just make everything count?

Nobody is saying that 'length' wouldn't make sense for JS arrays or the generic Qt containers. 'Length' does make perfect sense in that context.

What I've been trying to say that comparing JS array to QML ListModel is like comparing QList or QVector to QAbstractItemModel. That does not make sense. They have different APIs and different needs. They are not interchangeable components even if your code snippet attempts to make it look like that. While primitive containers can be used in any context, item models are deliberately designed to feed data to item views. That is the context where 'count' wins 'length' hands down.

J-P Nurmi
Interest mailing list
Interest at qt-project.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20160728/4c7ef8fb/attachment.html>

More information about the Interest mailing list