#include <qlist.h>
Collaboration diagram for QList< T >::iterator:

QList features both {STL-style iterators} and {Java-style iterators}. The STL-style iterators are more low-level and more cumbersome to use; on the other hand, they are slightly faster and, for developers who already know STL, have the advantage of familiarity.
QList<T>iterator allows you to iterate over a QList<T> (or QQueue<T>) and to modify the list item associated with the iterator. If you want to iterate over a const QList, use QList::const_iterator instead. It is generally good practice to use QList::const_iterator on a non-const QList as well, unless you need to change the QList through the iterator. Const iterators are slightly faster, and can improve code readability.
The default QList::iterator constructor creates an uninitialized iterator. You must initialize it using a QList function like QList::begin(), QList::end(), or QList::insert() before you can start iterating. Here's a typical loop that prints all the items stored in a list:
QList<QString> list; list.append("January"); list.append("February"); ... list.append("December"); QList<QString>::iterator i; for (i = list.begin(); i != list.end(); ++i) cout << *i << endl;
Let's see a few examples of things we can do with a QList::iterator that we cannot do with a QList::const_iterator. Here's an example that increments every value stored in a QList<int> by 2:
Most QList functions accept an integer index rather than an iterator. For that reason, iterators are rarely useful in connection with QList. One place where STL-style iterators do make sense is as arguments to {generic algorithms}.
For example, here's how to delete all the widgets stored in a QList<QWidget *>:
QList<QWidget *> list; ... qDeleteAll(list.begin(), list.end());
Multiple iterators can be used on the same list. However, be aware that any non-const function call performed on the QList will render all existing iterators undefined. If you need to keep iterators over a long period of time, we recommend that you use QLinkedList rather than QList.
Definition at line 128 of file qlist.h.
Public Types | |
| typedef std::random_access_iterator_tag | iterator_category |
| typedef ptrdiff_t | difference_type |
| typedef T | value_type |
| typedef T * | pointer |
| typedef T & | reference |
Public Member Functions | |
| iterator () | |
| iterator (Node *n) | |
| iterator (const iterator &o) | |
| T & | operator * () const |
| T * | operator-> () const |
| T & | operator[] (int j) const |
| bool | operator== (const iterator &o) const |
| bool | operator!= (const iterator &o) const |
| bool | operator< (const iterator &other) const |
| bool | operator<= (const iterator &other) const |
| bool | operator> (const iterator &other) const |
| bool | operator>= (const iterator &other) const |
| bool | operator== (const const_iterator &o) const |
| bool | operator!= (const const_iterator &o) const |
| bool | operator< (const const_iterator &other) const |
| bool | operator<= (const const_iterator &other) const |
| bool | operator> (const const_iterator &other) const |
| bool | operator>= (const const_iterator &other) const |
| iterator & | operator++ () |
| iterator | operator++ (int) |
| iterator & | operator-- () |
| iterator | operator-- (int) |
| iterator & | operator+= (int j) |
| iterator & | operator-= (int j) |
| iterator | operator+ (int j) const |
| iterator | operator- (int j) const |
| int | operator- (iterator j) const |
Public Attributes | |
| Node * | i |
| QList< T >::iterator::iterator_category |
| QList< T >::iterator::difference_type |
| QList< T >::iterator::value_type |
| QList< T >::iterator::pointer |
| QList< T >::iterator::reference |
| QList< T >::iterator::iterator | ( | ) | [inline] |
Constructs an uninitialized iterator.
Functions like operator*() and operator++() should not be called on an uninitialized iterartor. Use operator=() to assign a value to it before using it.
Definition at line 137 of file qlist.h.
Referenced by QList< T >::iterator::operator+(), and QList< T >::iterator::operator-().
00137 : i(0) {}
| T & QList< T >::iterator::operator * | ( | ) | const [inline] |
Returns a modifiable reference to the current item.
You can change the value of an item by using operator*() on the left side of an assignment, for example:
if (*it == "Hello") *it = "Bonjour";
Definition at line 140 of file qlist.h.
References QList< T >::iterator::i, and QList< T >::Node::t().
00140 { return i->t(); }
Here is the call graph for this function:

| T * QList< T >::iterator::operator-> | ( | ) | const [inline] |
Returns a pointer to the current item.
Definition at line 141 of file qlist.h.
References QList< T >::iterator::i, and QList< T >::Node::t().
00141 { return &i->t(); }
Here is the call graph for this function:

| T & QList< T >::iterator::operator[] | ( | int | j | ) | const [inline] |
Returns a modifiable reference to the item at position *this + {j}.
This function is provided to make QList iterators behave like C++ pointers.
Definition at line 142 of file qlist.h.
References QList< T >::iterator::i, and QList< T >::Node::t().
Here is the call graph for this function:

Definition at line 145 of file qlist.h.
References QList< T >::iterator::i.
00145 { return i < other.i; }
| bool QList< T >::iterator::operator<= | ( | const iterator & | other | ) | const [inline] |
Definition at line 146 of file qlist.h.
References QList< T >::iterator::i.
00146 { return i <= other.i; }
Definition at line 147 of file qlist.h.
References QList< T >::iterator::i.
00147 { return i > other.i; }
| bool QList< T >::iterator::operator>= | ( | const iterator & | other | ) | const [inline] |
Definition at line 148 of file qlist.h.
References QList< T >::iterator::i.
00148 { return i >= other.i; }
| bool QList< T >::iterator::operator== | ( | const const_iterator & | other | ) | const [inline] |
Returns true if other points to the same item as this iterator; otherwise returns false.
Definition at line 150 of file qlist.h.
References QList< T >::iterator::i, and o.
| bool QList< T >::iterator::operator!= | ( | const const_iterator & | other | ) | const [inline] |
Returns true if other points to a different item than this iterator; otherwise returns false.
Definition at line 152 of file qlist.h.
References QList< T >::iterator::i, and o.
| bool QList< T >::iterator::operator< | ( | const const_iterator & | other | ) | const [inline] |
Returns true if the item pointed to by this iterator is less than the item pointed to by the other iterator.
Definition at line 154 of file qlist.h.
References QList< T >::iterator::i.
00155 { return i < reinterpret_cast<const iterator &>(other).i; }
| bool QList< T >::iterator::operator<= | ( | const const_iterator & | other | ) | const [inline] |
Returns true if the item pointed to by this iterator is less than or equal to the item pointed to by the other iterator.
Definition at line 156 of file qlist.h.
References QList< T >::iterator::i.
00157 { return i <= reinterpret_cast<const iterator &>(other).i; }
| bool QList< T >::iterator::operator> | ( | const const_iterator & | other | ) | const [inline] |
Returns true if the item pointed to by this iterator is greater than the item pointed to by the other iterator.
Definition at line 158 of file qlist.h.
References QList< T >::iterator::i.
| bool QList< T >::iterator::operator>= | ( | const const_iterator & | other | ) | const [inline] |
Returns true if the item pointed to by this iterator is greater than or equal to the item pointed to by the other iterator.
Definition at line 160 of file qlist.h.
References QList< T >::iterator::i.
| QList::iterator & QList< T >::iterator::operator++ | ( | ) | [inline] |
The prefix ++ operator ({++it}) advances the iterator to the next item in the list and returns an iterator to the new current item.
Calling this function on QList::end() leads to undefined results.
Definition at line 163 of file qlist.h.
References QList< T >::iterator::i.
00163 { ++i; return *this; }
| QList::iterator QList< T >::iterator::operator++ | ( | int | ) | [inline] |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. The postfix ++ operator ({it++}) advances the iterator to the next item in the list and returns an iterator to the previously current item.
Definition at line 164 of file qlist.h.
References QList< T >::iterator::i, and n.
| QList::iterator & QList< T >::iterator::operator-- | ( | ) | [inline] |
The prefix -- operator ({--it}) makes the preceding item current and returns an iterator to the new current item.
Calling this function on QList::begin() leads to undefined results.
Definition at line 165 of file qlist.h.
References QList< T >::iterator::i.
00165 { i--; return *this; }
| QList::iterator QList< T >::iterator::operator-- | ( | int | ) | [inline] |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. The postfix -- operator ({it--}) makes the preceding item current and returns an iterator to the previously current item.
Definition at line 166 of file qlist.h.
References QList< T >::iterator::i, and n.
| QList::iterator & QList< T >::iterator::operator+= | ( | int | j | ) | [inline] |
Advances the iterator by j items. (If j is negative, the iterator goes backward.)
Definition at line 167 of file qlist.h.
References QList< T >::iterator::i.
| QList::iterator & QList< T >::iterator::operator-= | ( | int | j | ) | [inline] |
Makes the iterator go back by j items. (If j is negative, the iterator goes forward.)
Definition at line 168 of file qlist.h.
References QList< T >::iterator::i.
| QList::iterator QList< T >::iterator::operator+ | ( | int | j | ) | const [inline] |
Returns an iterator to the item at j positions forward from this iterator. (If j is negative, the iterator goes backward.)
Definition at line 169 of file qlist.h.
References QList< T >::iterator::i, and QList< T >::iterator::iterator().
Here is the call graph for this function:

| QList::iterator QList< T >::iterator::operator- | ( | int | j | ) | const [inline] |
Returns an iterator to the item at j positions backward from this iterator. (If j is negative, the iterator goes forward.)
Definition at line 170 of file qlist.h.
References QList< T >::iterator::i, and QList< T >::iterator::iterator().
Here is the call graph for this function:

| Node* QList< T >::iterator::i |
Definition at line 130 of file qlist.h.
Referenced by QList< T >::erase(), QList< T >::insert(), QList< T >::iterator::operator *(), QList< T >::iterator::operator!=(), QList< T >::iterator::operator+(), QList< T >::iterator::operator++(), QList< T >::iterator::operator+=(), QList< T >::iterator::operator-(), QList< T >::iterator::operator--(), QList< T >::iterator::operator-=(), QList< T >::iterator::operator->(), QList< T >::iterator::operator<(), QList< T >::iterator::operator<=(), QList< T >::iterator::operator==(), QList< T >::iterator::operator>(), QList< T >::iterator::operator>=(), and QList< T >::iterator::operator[]().
1.5.1