mozzbozz
mozzbozz

Reputation: 3153

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

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?

Upvotes: 5

Views: 11417

Answers (2)

Antwane
Antwane

Reputation: 22688

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.

Upvotes: 11

onezeno
onezeno

Reputation: 774

There are two count methods, one which takes parameters, and one which does not. If you look at the source, you can see that length(), size(), and count all have the same implementation (return p.size();), and int QList<T>::count(const T &t) const has another implementation.

Upvotes: 3

Related Questions