QList: Difference between length() and count() functions?

mozzbozz picture mozzbozz · Sep 17, 2014 · Viewed 7.3k times · Source

I'm wondering what the difference between the functions QList::length() and QList::count() really is.

The docs say:

int QList::length() const

This function is identical to count().

int QList::count(const T & value) const

Returns the number of occurrences of value in the list.

This function requires the value type to have an implementation of operator==().

But how can a function without parameters (length()) be the same as one with parameters (count())? The description of the count()-function makes sense for me.

However, what does the length()-function exactly do? Did they mean that it is the same as the size()-function of QList?

Answer

Antwane picture Antwane · Sep 17, 2014

int QList::length() const is NOT equivalent to int QList::count(const T & value) const but to int QList::count() const (see the next signature for the count() method).

The right link: http://doc.qt.io/qt-5/qlist.html#count-1

In QList class, methods length(), size() and count() (without parameter) are equivalent and will return the same result.