QAssociativeIterable 类是关联容器的可迭代接口,在 QVariant . 更多...
头: | #include <QAssociativeIterable> |
CMake: |
find_package(Qt6 REQUIRED COMPONENTS Core)
target_link_libraries(mytarget PRIVATE Qt6::Core) |
qmake: | QT += core |
继承: | QIterable |
BidirectionalConstIterator | |
BidirectionalIterator | |
ForwardConstIterator | |
ForwardIterator | |
InputConstIterator | |
InputIterator | |
RandomAccessConstIterator | |
RandomAccessIterator | |
const_iterator | |
(从 6.0 起)
|
iterator |
bool | containsKey (const QVariant & key ) |
QAssociativeIterable::const_iterator | find (const QVariant & key ) const |
void | insertKey (const QVariant & key ) |
QAssociativeIterable::iterator | mutableFind (const QVariant & key ) |
void | removeKey (const QVariant & key ) |
void | setValue (const QVariant & key , const QVariant & mapped ) |
QVariant | value (const QVariant & key ) const |
此类允许一些方法访问关联容器的元素,保持在 QVariant 。可以提取 QAssociativeIterable 的实例,从 QVariant 若它可以被转换成 QVariantHash or QVariantMap or if a custom mutable view has been registered.
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 .
[alias]
QAssociativeIterable::
BidirectionalConstIterator
Exposes a const_iterator using std::bidirectional_iterator_tag.
[alias]
QAssociativeIterable::
BidirectionalIterator
Exposes an iterator using std::bidirectional_iterator_tag.
[alias]
QAssociativeIterable::
ForwardConstIterator
Exposes a const_iterator using std::forward_iterator_tag.
[alias]
QAssociativeIterable::
ForwardIterator
Exposes an iterator using std::forward_iterator_tag.
[alias]
QAssociativeIterable::
InputConstIterator
Exposes a const_iterator using std::input_iterator_tag.
[alias]
QAssociativeIterable::
InputIterator
Exposes an iterator using std::input_iterator_tag.
[alias]
QAssociativeIterable::
RandomAccessConstIterator
Exposes a const_iterator using std::random_access_iterator_tag.
[alias]
QAssociativeIterable::
RandomAccessIterator
Exposes an iterator using std::random_access_iterator_tag.
[alias]
QAssociativeIterable::
const_iterator
The QAssociativeIterable::const_iterator allows iteration over a container in a QVariant .
A QAssociativeIterable::const_iterator can only be created by a QAssociativeIterable instance, and can be used in a way similar to other stl-style iterators.
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(); } }
另请参阅 QAssociativeIterable .
[alias, since 6.0]
QAssociativeIterable::
iterator
The QAssociativeIterable::iterator allows iteration over a container in a QVariant .
A QAssociativeIterable::iterator can only be created by a QAssociativeIterable instance, and can be used in a way similar to other stl-style iterators.
This typedef was introduced in Qt 6.0.
另请参阅 QAssociativeIterable .
返回
true
if the container has an entry with the given
key
,或
false
otherwise. If the
key
isn't convertible to the expected type,
false
被返回。
Retrieves a const_iterator pointing to the element at the given key , or the end of the container if that key does not exist. If the key isn't convertible to the expected type, the end of the container is returned.
Inserts a new entry with the given key , or resets the mapped value of any existing entry with the given key to the default constructed mapped value. The key is coerced to the expected type: If it isn't convertible, a default value is inserted.
Retrieves an iterator pointing to the element at the given key , or the end of the container if that key does not exist. If the key isn't convertible to the expected type, the end of the container is returned.
Removes the entry with the given key from the container. The key is coerced to the expected type: If it isn't convertible, the default value is removed.
Sets the mapped value associated with key to mapped , if possible. Inserts a new entry if none exists yet, for the given key 。若 key is not convertible to the key type, the value for the default-constructed key type is overwritten.
另请参阅 value ().
Retrieves the mapped value at the given key , or a default-constructed QVariant of the mapped type, if the key does not exist. If the key is not convertible to the key type, the mapped value associated with the default-constructed key is returned.
另请参阅 setValue ().