6.0.0-rc4Source

QSequentialIterable Class

The QSequentialIterable class is an iterable interface for a container in a QVariant. More…

Header#include <QSequentialIterable>
CMaketarget_link_libraries(app PRIVATE Nt::Core)
ModuleNt Core C++ Classes

List of all members, including inherited members

Public Functions

QSequentialIterable(const QVariant &variant)
QSequentialIterable(const QSequentialIterable &other)
QSequentialIterable &operator=(const QSequentialIterable &other)
~QSequentialIterable()
boolisValid() const
qsizetypesize() const
QVariantat(qsizetype idx) const
const_iteratorbegin() const
const_iteratorend() const
const_iteratorconstBegin() const
const_iteratorconstEnd() const
QMetaTypevalueMetaType() const
boolcanReverseIterate() const

Detailed Description

A QVariant that holds a sequential container, such as QList<int>, std::vector<QString>, QSet or QStringList, converts to a QSequentialIterable. It reads the elements as QVariant objects without knowing the container type:

QVariant v = QVariant::fromValue(QList<int>{1, 2, 3});
if (v.canConvert<QSequentialIterable>()) {
    QSequentialIterable it = v.value<QSequentialIterable>();
    for (const QVariant &e : it)
        qDebug() << e.toInt();
}

The element type must be registered with QMetaType, which happens automatically for the types Nt knows and for types that are declared with Q_DECLARE_METATYPE().

See also QAssociativeIterable, QVariant and QMetaType.

Differences from Qt

The iterable works on a copy of the variant, so it is read-only: there is no addValue(), removeValue() or mutableBegin(). There is no metaContainer(), and canReverseIterate() is always true.

Member Function Documentation

[explicit] QSequentialIterable::QSequentialIterable(const QVariant &variant)

Constructs an iterable for the container that variant holds. The result is not valid if the variant does not hold a sequential container.

See also isValid().

QSequentialIterable::QSequentialIterable(const QSequentialIterable &other)

Constructs a copy of other.

QSequentialIterable::~QSequentialIterable()

Destroys the iterable.

QVariant QSequentialIterable::at(qsizetype idx) const

Returns the element at the position idx as a QVariant, or an invalid variant if idx is out of range.

const_iterator QSequentialIterable::begin() const

Returns an iterator to the first element.

See also end() and constBegin().

bool QSequentialIterable::canReverseIterate() const

Returns true if the container can be iterated backwards. Every container Nt supports can.

const_iterator QSequentialIterable::constBegin() const

Returns an iterator to the first element.

See also begin() and constEnd().

const_iterator QSequentialIterable::constEnd() const

Returns an iterator past the last element.

See also end() and constBegin().

const_iterator QSequentialIterable::end() const

Returns an iterator past the last element.

See also begin() and constEnd().

bool QSequentialIterable::isValid() const

Returns true if the iterable refers to a container.

QSequentialIterable & QSequentialIterable::operator=(const QSequentialIterable &other)

Assigns other to this iterable and returns a reference to it.

qsizetype QSequentialIterable::size() const

Returns the number of elements, or 0 if the iterable is not valid.

QMetaType QSequentialIterable::valueMetaType() const

Returns the QMetaType of the elements, or an invalid QMetaType if the iterable is not valid.