如何知道基于项目的ListView QT C 中是否存在字符串

How to know if a string exist in a item based ListView Qt C++

本文关键字:QT ListView 是否 字符串 存在 何知道 于项目 项目      更新时间:2023-10-16

我想知道在列表中的任何一项中是否存在一个字符串,c with qt,如何做?

也许这个小的迭代函数可以做到您要寻找的东西:

bool doesContain(QListView *listView, QString expression)
{
    QAbstractItemModel* model = listView->model() ;
    int rowCount = model->rowCount();
    int columnCount = model->columnCount();
    for(int i = 0; i < rowCount; i++)
        for(int j = 0; j < columnCount; j++)
            if(model->index(i, j).data(Qt::DisplayRole).toString().contains(expression))
                return true;
    return false;
}