im setting item's in QListWidget and in each QListWidgetItem im se开发者_JS百科tting id like this:
newItem->setData(Qt::DisplayRole,ID);
now each time before im adding the itemi wish to check if already there is item with the same data in the list . how can i do that ... i don't think the findItems will help me here
Let me assume that type of ID
is int
(cause you didn't specify it).
bool found = false;
for (int i = 0; i < list->count(); ++i) {
if (list->item(i)->data(Qt::DisplayRole).toInt() == ID_to_match) {
found = true;
break;
}
}
if (!found) {
do_something_here();
}
精彩评论