Hi,

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.


Regards,

Michael

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

On Thursday, July 28, 2016 15:46, Jason H <jh...@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@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest
_______________________________________________
Interest mailing list
Interest@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest

Reply via email to