可以使用QList中的count函数来查找指定元素的出现次数。以下是一个示例代码:

#include <QList>
#include <QDebug>

int main() {
    QList<int> list;
    list << 1 << 2 << 3 << 2 << 4 << 2 << 5;

    int index = 2;
    int count = list.count(list.at(index));

    qDebug() << "Element at index" << index << "occurs" << count << "times";

    return 0;
}

运行结果为:

Element at index 2 occurs 3 times

在上述示例中,我们创建了一个包含一些整数的QList。然后,我们指定了要查找的元素的索引(这里是2),并使用count函数来计算该元素在列表中出现的次数。最后,我们使用qDebug输出结果。

Qt 查找QListint中指定index对应的元素出现的次数

原文地址: http://www.cveoy.top/t/topic/ii1N 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录