The QAssociativeIterable class is an iterable interface for an associative container in a QVariant . 更多...
| 頭: | #include <QAssociativeIterable> |
| qmake: | QT += core |
| Since: | Qt 5.2 |
| class | 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 |
The QAssociativeIterable class is an iterable interface for an associative container in a QVariant .
此類允許一些方法訪問關聯容器的元素,保持在 QVariant . An instance of QAssociativeIterable can be extracted from a 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 ().