|
| key_iterator () noexcept=default |
|
| key_iterator (const_iterator o) noexcept |
|
const Key & | operator* () const noexcept |
| Returns the current item's key.
|
|
const Key * | operator-> () const noexcept |
| Returns a pointer to the current item's key.
|
|
bool | operator== (key_iterator o) const noexcept |
| Returns true if other points to the same item as this iterator; otherwise returns false .
|
|
bool | operator!= (key_iterator o) const noexcept |
| Returns true if other points to a different item than this iterator; otherwise returns false .
|
|
key_iterator & | operator++ () noexcept |
| The prefix ++ operator ( {++i}) advances the iterator to the next item in the hash and returns an iterator to the new current item.
|
|
key_iterator | operator++ (int) noexcept |
| 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 ( {i++}) advances the iterator to the next item in the hash and returns an iterator to the previous item.
|
|
const_iterator | base () const noexcept |
| Returns the underlying const_iterator this key_iterator is based on.
|
|
template<typename
Key, typename T>
class QHash< Key, T >::key_iterator
\inmodule QtCore
- Since
- 5.6
The QHash::key_iterator class provides an STL-style const iterator for QHash keys.
QHash::key_iterator is essentially the same as QHash::const_iterator with the difference that operator*() and operator->() return a key instead of a value.
For most uses QHash::iterator and QHash::const_iterator should be used, you can easily access the key by calling QHash::iterator::key():
cout <<
"The key: " <<
it.key() << endl;
}
However, to have interoperability between QHash's keys and STL-style algorithms we need an iterator that dereferences to a key instead of a value. With QHash::key_iterator we can apply an algorithm to a range of keys without having to call QHash::keys(), which is inefficient as it costs one QHash iteration and memory allocation to create a temporary QList.
int numPrimes = std::count_if(
keys.cbegin(),
keys.cend(), isPrimeNumber);
int numPrimes = std::count_if(
hash.keyBegin(),
hash.keyEnd(), isPrimeNumber);
QHash::key_iterator is const, it's not possible to modify the key.
The default QHash::key_iterator constructor creates an uninitialized iterator. You must initialize it using a QHash function like QHash::keyBegin() or QHash::keyEnd().
- Warning
- Iterators on implicitly shared containers do not work exactly like STL-iterators. You should avoid copying a container while iterators are active on that container. For more information, read \l{Implicit sharing iterator problem}.
- See also
- QHash::const_iterator, QHash::iterator
Definition at line 1209 of file qhash.h.