QAssociativeIterable Class
The QAssociativeIterable class is an iterable interface for an associative container in a QVariant. More…
| Header | #include <QAssociativeIterable> |
|---|---|
| CMake | target_link_libraries(app PRIVATE Nt::Core) |
| Module | Nt Core C++ Classes |
List of all members, including inherited members
Public Functions
| QAssociativeIterable(const QVariant &variant) | |
| QAssociativeIterable(const QAssociativeIterable &other) | |
| QAssociativeIterable & | operator=(const QAssociativeIterable &other) |
| ~QAssociativeIterable() | |
| bool | isValid() const |
| qsizetype | size() const |
| const_iterator | begin() const |
| const_iterator | end() const |
| const_iterator | constBegin() const |
| const_iterator | constEnd() const |
| const_iterator | find(const QVariant &key) const |
| const_iterator | constFind(const QVariant &key) const |
| bool | containsKey(const QVariant &key) const |
| QVariant | value(const QVariant &key) const |
| QMetaType | keyMetaType() const |
| QMetaType | mappedMetaType() const |
Detailed Description
A QVariant that holds an associative container, such as QMap<QString, int>, QHash or std::map, converts to a QAssociativeIterable, which reads the entries as QVariant objects:
QVariant v = QVariant::fromValue(QMap<QString, int>{{"a", 1}, {"b", 2}});
QAssociativeIterable it = v.value<QAssociativeIterable>();
for (auto i = it.begin(); i != it.end(); ++i)
qDebug() << i.key().toString() << i.value().toInt();
See also QSequentialIterable, QVariant and QMetaType.
Differences from Qt
The iterable works on a copy of the variant, so it is read-only: there is no insert() or remove(). There is no metaContainer() and no operator[]; use value().
Member Function Documentation
QAssociativeIterable::QAssociativeIterable(const QVariant &variant)
Constructs an iterable for the container that variant holds. The result is not valid if the variant does not hold an associative container.
See also isValid().
QAssociativeIterable::QAssociativeIterable(const QAssociativeIterable &other)
Constructs a copy of other.
QAssociativeIterable::~QAssociativeIterable()
Destroys the iterable.
const_iterator QAssociativeIterable::begin() const
Returns an iterator to the first entry.
See also end() and constBegin().
const_iterator QAssociativeIterable::constBegin() const
Returns an iterator to the first entry.
See also begin() and constEnd().
const_iterator QAssociativeIterable::constEnd() const
Returns an iterator past the last entry.
See also end() and constBegin().
const_iterator QAssociativeIterable::constFind(const QVariant &key) const
Returns an iterator to the entry with key, or end() if there is none.
See also find().
bool QAssociativeIterable::containsKey(const QVariant &key) const
Returns true if the container has an entry with key.
const_iterator QAssociativeIterable::end() const
Returns an iterator past the last entry.
See also begin() and constEnd().
const_iterator QAssociativeIterable::find(const QVariant &key) const
Returns an iterator to the entry with key, or end() if there is none or key cannot be converted to the key type.
See also constFind() and containsKey().
bool QAssociativeIterable::isValid() const
Returns true if the iterable refers to a container.
QMetaType QAssociativeIterable::keyMetaType() const
Returns the QMetaType of the keys, or an invalid QMetaType if the iterable is not valid.
QMetaType QAssociativeIterable::mappedMetaType() const
Returns the QMetaType of the mapped values, or an invalid QMetaType if the iterable is not valid.
QAssociativeIterable & QAssociativeIterable::operator=(const QAssociativeIterable &other)
Assigns other to this iterable and returns a reference to it.
qsizetype QAssociativeIterable::size() const
Returns the number of entries, or 0 if the iterable is not valid.
QVariant QAssociativeIterable::value(const QVariant &key) const
Returns the mapped value of the entry with key, or an invalid variant if there is none.
See also find() and containsKey().