Reputation: 1640
I want to know if a string exists in any item of a list view in C++ with Qt, how to do that ?
Upvotes: 0
Views: 745
Reputation: 4668
Perhaps this little iterating function does what you're looking for:
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;
}
Upvotes: 3