遍历元素 1:foreach 方式
1 2 3 4 5 6 7 8 9 |
// QList<outNode*> list; foreach (outNode *i, list) { if (i->sn == tmpNode->sn) { qDebug() << "find in list!"; } } |
2:for 方式
1 2 3 4 5 6 7 8 9 10 11 12 13 |
// QList<outNode*> list; for (int i = 0; i < list.size(); ++i) { outNode *node = (outNode *)list.at(i); if (node->sn == tmpNode->sn) { qDebug() << "find in database!"; list.removeAt(i); // 删除 list.append(tmpNode); // 添加 return; } } |