自學QT之QListIterator迭代器的示例

#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);
    }
    QListIterator<int> myiter(mylist);
    while(myiter.hasNext())
    {
        qDebug()<< myiter.next();
    }

    return a.exec();
}

這是一個使用QListIterator迭代器的示例。QListIterator是一個java風格的迭代器,能夠實現遍歷輸出list的內容。java

QListIterator的函數有:app

QListIterator(const QList<T> & list) bool     findNext(const T & value) bool     findPrevious(const T & value) bool     hasNext() const bool     hasPrevious() const const T &     next() const T &     peekNext() const const T &     peekPrevious() const const T &     previous() void     toBack() void     toFront() QListIterator &     operator=(const QList<T> & list)
相關文章
相關標籤/搜索