QList: length()和count()函数的差异?

时间:2022-05-24 18:29:22

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

我想知道函数QList::length()和QList::count()的区别是什么。

The docs say:

医生说:

int QList::length() const

This function is identical to count().

这个函数与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.

但是,没有参数的函数(长度())如何与参数(count())相同?对我来说,count()函数的描述是有意义的。

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

但是,length()函数到底是做什么的呢?它们是否意味着它与QList的size()函数相同?

2 个解决方案

#1


6  

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).

int QList::length() const并不等同于int QList::count(const T & value) const,但对于int QList::count() const(参见下一个对count()方法的签名)。

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

正确的链接:http://doc.qt.io/qt-5/qlist.html把1

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

在QList类中,方法length()、size()和count()(没有参数)是等价的,并且将返回相同的结果。

#2


2  

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.

有两种计数方法,一种采用参数,另一种不采用参数。如果查看源代码,可以看到length()、size()和count都有相同的实现(return .size();)和int QList ::count(const t&t) const有另一个实现。

#1


6  

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).

int QList::length() const并不等同于int QList::count(const T & value) const,但对于int QList::count() const(参见下一个对count()方法的签名)。

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

正确的链接:http://doc.qt.io/qt-5/qlist.html把1

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

在QList类中,方法length()、size()和count()(没有参数)是等价的,并且将返回相同的结果。

#2


2  

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.

有两种计数方法,一种采用参数,另一种不采用参数。如果查看源代码,可以看到length()、size()和count都有相同的实现(return .size();)和int QList ::count(const t&t) const有另一个实现。