The QMultiHashIterator class provides a Java style const iterator for QMultiHash.
More...
template<typename Key, typename Val, typename Hash, typename KeyEqual>
class QMultiHashIterator< Key, Val, Hash, KeyEqual >
The QMultiHashIterator class provides a Java style const iterator for QMultiHash. QMultiHash has both Java style iterators and STL style iterators.
QMultiHashIterator allows you to iterate over a QMultiHash. If you want to modify the hash as you iterate over it, use QMutableMultiHashIterator instead.
After construction the iterator is located at the very beginning of the hash, before the first item. The following code shows how to iterate over all the elements sequentially.
while (iter.hasNext()) {
iter.next();
}
The next() method returns the next item in the hash and advances the iterator. The key() and value() methods return the key and value of the last item which was jumped over.
Unlike STL style iterators, Java style iterators point between items rather than directly at items. The first call to next() advances the iterator to the position between the first and second item, and returns the first item; the second call to next() advances the iterator to the position between the second and third item, and so on.

Here is how to iterate over the elements in reverse order:
iter.toBack();
while (iter.hasPrevious()) {
iter.previous();
}
If you want to find all occurrences of a particular value, use findNext() or findPrevious().
while (iter.findNext(widget)) {
qDebug() <<
"Found widget " << widget <<
" under key " << iter.key();
}
- See also
- QMutableMultiHashIterator
template<typename Key , typename Val , typename Hash , typename KeyEqual >
bool QMultiHashIterator< Key, Val, Hash, KeyEqual >::findNext |
( |
const Val & |
value | ) |
|
|
inline |
Searches for value starting from the current iterator position and moving forward. Returns true if a (key, value) pair with the specified value is found, otherwise it returns false. If value is found the iterator is positioned just after the matching item, otherwise the iterator is positioned at the end of the container.
- See also
- findPrevious()
template<typename Key , typename Val , typename Hash , typename KeyEqual >
bool QMultiHashIterator< Key, Val, Hash, KeyEqual >::findPrevious |
( |
const Val & |
value | ) |
|
|
inline |
Searches for value starting from the current iterator position and moving backward. Returns true if a (key, value) pair with the specified value is found, otherwise it returns false. If value was found the iterator is positioned just before the matching item. Otherwise the iterator is positioned at the beginning of the container.
- See also
- findNext()