开发者

In QListWidget how do i check if QListWidgetItem already exists based on its Data member

开发者 https://www.devze.com 2023-02-21 04:00 出处:网络
im setting item\'s in QListWidget and in each QListWidgetItem im se开发者_JS百科tting id like this:

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();
}
0

精彩评论

暂无评论...
验证码 换一张
取 消