QSequentialIterable Class▲
-
Header: QSequentialIterable
-
Since: Qt 5.2
-
qmake: QT += core
Detailed Description▲
This class allows several methods of accessing the elements of a container held within a QVariant. An instance of QSequentialIterable can be extracted from a QVariant if it can be converted to a QVariantList.
QList&
lt;int
&
gt; intList =
{
7
, 11
, 42
}
;
QVariant variant =
QVariant::
fromValue(intList);
if
(variant.canConvert&
lt;QVariantList&
gt;()) {
QSequentialIterable iterable =
variant.value&
lt;QSequentialIterable&
gt;();
// Can use foreach:
foreach (const
QVariant &
amp;v, iterable) {
qDebug() &
lt;&
lt; v;
}
// Can use C++11 range-for:
for
(const
QVariant &
amp;v : iterable) {
qDebug() &
lt;&
lt; v;
}
// Can use iterators:
QSequentialIterable::
const_iterator it =
iterable.begin();
const
QSequentialIterable::
const_iterator end =
iterable.end();
for
( ; it !=
end; ++
it) {
qDebug() &
lt;&
lt; *
it;
}
}
The container itself is not copied before iterating over it.
See Also▲
See also QVariant
Member Function Documentation▲
QVariant QSequentialIterable::at(int idx) const▲
Returns the element at position idx in the container.
QSequentialIterable::const_iterator QSequentialIterable::begin() const▲
Returns a QSequentialIterable::const_iterator for the beginning of the container. This can be used in stl-style iteration.
See Also▲
See also end()
bool QSequentialIterable::canReverseIterate() const▲
Returns whether it is possible to iterate over the container in reverse. This corresponds to the std::bidirectional_iterator_tag iterator trait of the const_iterator of the container.
QSequentialIterable::const_iterator QSequentialIterable::end() const▲
Returns a QSequentialIterable::const_iterator for the end of the container. This can be used in stl-style iteration.
See Also▲
See also begin()
int QSequentialIterable::size() const▲
Returns the number of elements in the container.