▲
-
Header: const_iterator
-
Since: Qt 5.2
-
qmake: QT += core
Detailed Description▲
A QAssociativeIterable::const_iterator can only be created by a QAssociativeIterable instance, and can be used in a way similar to other stl-style iterators.
QHash&
lt;int
, QString&
gt; mapping;
mapping.insert(7
, "Seven"
);
mapping.insert(11
, "Eleven"
);
mapping.insert(42
, "Forty-two"
);
QVariant variant =
QVariant::
fromValue(mapping);
if
(variant.canConvert&
lt;QVariantHash&
gt;()) {
QAssociativeIterable iterable =
variant.value&
lt;QAssociativeIterable&
gt;();
// Can use foreach over the values:
foreach (const
QVariant &
amp;v, iterable) {
qDebug() &
lt;&
lt; v;
}
// Can use C++11 range-for over the values:
for
(const
QVariant &
amp;v : iterable) {
qDebug() &
lt;&
lt; v;
}
// Can use iterators:
QAssociativeIterable::
const_iterator it =
iterable.begin();
const
QAssociativeIterable::
const_iterator end =
iterable.end();
for
( ; it !=
end; ++
it) {
qDebug() &
lt;&
lt; *
it; // The current value
qDebug() &
lt;&
lt; it.key();
qDebug() &
lt;&
lt; it.value();
}
}
See Also▲
See also QAssociativeIterable
Member Function Documentation▲
const_iterator::const_iterator(const const_iterator &other)▲
Creates a copy of other.
const_iterator::~const_iterator()▲
Destroys the QAssociativeIterable::const_iterator.
const QVariant const_iterator::key() const▲
Returns the current key, converted to a QVariant.
const QVariant const_iterator::value() const▲
Returns the current value, converted to a QVariant.
bool const_iterator::operator!=(const const_iterator &other) const▲
Returns true if other points to a different item than this iterator; otherwise returns false.
See Also▲
See also operator==()
const QVariant const_iterator::operator*() const▲
Returns the current value, converted to a QVariant.
const_iterator const_iterator::operator+(int j) const▲
Returns an iterator to the item at j positions forward from this iterator.
See Also▲
See also operator-(), operator+=()
const_iterator &const_iterator::operator++()▲
The prefix ++ operator (++it) advances the iterator to the next item in the container and returns an iterator to the new current item.
Calling this function on QAssociativeIterable::end() leads to undefined results.
See Also▲
See also operator--()
const_iterator const_iterator::operator++(int)▲
This is an overloaded function.
The postfix ++ operator (it++) advances the iterator to the next item in the container and returns an iterator to the previously current item.
const_iterator &const_iterator::operator+=(int j)▲
const_iterator const_iterator::operator-(int j) const▲
Returns an iterator to the item at j positions backward from this iterator.
See Also▲
See also operator+(), operator-=()
const_iterator &const_iterator::operator--()▲
The prefix – operator (--it) makes the preceding item current and returns an iterator to the new current item.
Calling this function on QAssociativeIterable::begin() leads to undefined results.
See Also▲
See also operator++()
const_iterator const_iterator::operator--(int)▲
This is an overloaded function.
The postfix – operator (it--) makes the preceding item current and returns an iterator to the previously current item.
const_iterator &const_iterator::operator-=(int j)▲
const_iterator &const_iterator::operator=(const const_iterator &other)▲
Assigns other to this.
bool const_iterator::operator==(const const_iterator &other) const▲
Returns true if other points to the same item as this iterator; otherwise returns false.
See Also▲
See also operator!=()