#include <QCoreApplication> #include <QList> #include <QDebug> int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); QList<int> mylist; for(int i=0;i<10;i++) { mylist.append(i); } QMutableListIterator<int> iter(mylist); while(iter.hasNext()) { int i=iter.next(); if(i==5) { iter.remove(); } } iter.toFront(); while(iter.hasNext()) { qDebug()<<iter.next(); } return a.exec(); }
上面代码运行的结果:
官方给出的函数有:
QMutableListIterator(QList<T> & list) | |
~QMutableListIterator() | |
bool | findNext(const T & value) |
bool | findPrevious(const T & value) |
bool | hasNext() const |
bool | hasPrevious() const |
void | insert(const T & value) |
T & | next() |
T & | peekNext() const |
T & | peekPrevious() const |
T & | previous() |
void | remove() |
void | setValue(const T & value) const |
void | toBack() |
void | toFront() |
const T & | value() const |
T & | value() |
QMutableListIterator & | operator=(QList<T> & list) |