QAssociativeIterable 类是关联容器的可迭代接口,在 QVariant . 更多...
头: | #include <QAssociativeIterable> |
qmake: | QT += core |
Since: | Qt 5.2 |
该类在 Qt 5.2 引入。
struct | const_iterator |
QAssociativeIterable::const_iterator | begin () const |
QAssociativeIterable::const_iterator | end () const |
QAssociativeIterable::const_iterator | find (const QVariant & key ) const |
int | size () const |
QVariant | value (const QVariant & key ) const |
此类允许一些方法访问关联容器的元素,保持在 QVariant 。可以提取 QAssociativeIterable 的实例,从 QVariant 若它可以被转换成 QVariantHash or QVariantMap .
QHash<int, QString> mapping; mapping.insert(7, "Seven"); mapping.insert(11, "Eleven"); mapping.insert(42, "Forty-two"); QVariant variant = QVariant::fromValue(mapping); if (variant.canConvert<QVariantHash>()) { QAssociativeIterable iterable = variant.value<QAssociativeIterable>(); // Can use foreach over the values: foreach (const QVariant &v, iterable) { qDebug() << v; } // Can use C++11 range-for over the values: for (const QVariant &v : iterable) { qDebug() << v; } // Can use iterators: QAssociativeIterable::const_iterator it = iterable.begin(); const QAssociativeIterable::const_iterator end = iterable.end(); for ( ; it != end; ++it) { qDebug() << *it; // The current value qDebug() << it.key(); qDebug() << it.value(); } }
容器本身不会被拷贝,在遍历它之前。
另请参阅 QVariant .
返回 QAssociativeIterable::const_iterator for the beginning of the container. This can be used in stl-style iteration.
另请参阅 end ().
返回 QAssociativeIterable::const_iterator for the end of the container. This can be used in stl-style iteration.
另请参阅 begin ().
返回 QAssociativeIterable::const_iterator for the given key key in the container, if the types are convertible.
若找不到键,返回 end ().
This can be used in stl-style iteration.
该函数在 Qt 5.5 引入。
另请参阅 begin (), end (),和 value ().
Returns the number of elements in the container.
Returns the value for the given key in the container, if the types are convertible.
另请参阅 find ().