Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

qt

qlist

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?

like image 546
mozzbozz Avatar asked Dec 19 '22 11:12

mozzbozz


1 Answers

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.

like image 77
Antwane Avatar answered Jan 08 '23 13:01

Antwane