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