这是一个可变的迭代器,它可以改变底层的数据而普通的迭代器是不可以的。
#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) |