本页内容

QAssociativeIterable Class

QAssociativeIterable 类是QVariant 中关联容器的可迭代接口。更多内容...

头文件: #include <QAssociativeIterable>
CMake: find_package(Qt6 REQUIRED COMPONENTS Core)
target_link_libraries(mytarget PRIVATE Qt6::Core)
qmake: QT += core
继承自: QIterable
状态: 截至 6.15 版本

该类计划在 6.15 版本中被废弃。

公共类型

公共函数

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

详细说明

请改用QMetaAssociation::Iterable 。

该类提供了多种方法,用于访问QVariant 中包含的关联容器的元素。如果QVariant 可以转换为QVariantHash 或QVariantMap ,或者已注册了自定义的可变视图,则可以从 中提取QAssociativeIterable的实例。

在遍历容器之前,不会复制容器本身。

另请参阅 QVariant 。

成员类型文档

[alias] QAssociativeIterable::BidirectionalConstIterator

使用 std::bidirectional_iterator_tag 暴露一个const_iterator 。

[alias] QAssociativeIterable::BidirectionalIterator

使用 std::bidirectional_iterator_tag 暴露一个迭代器。

[alias] QAssociativeIterable::ForwardConstIterator

使用 std::forward_iterator_tag 暴露一个const_iterator 。

[alias] QAssociativeIterable::ForwardIterator

使用 std::forward_iterator_tag 暴露一个迭代器。

[alias] QAssociativeIterable::InputConstIterator

使用 std::input_iterator_tag 暴露一个const_iterator 。

[alias] QAssociativeIterable::InputIterator

使用 std::input_iterator_tag 公开一个迭代器。

[alias] QAssociativeIterable::RandomAccessConstIterator

使用 std::random_access_iterator_tag 暴露一个const_iterator 。

[alias] QAssociativeIterable::RandomAccessIterator

使用 std::random_access_iterator_tag 公开一个迭代器。

[alias, until 6.15] QAssociativeIterable::const_iterator

该 typedef 计划在 6.15 版本中被废弃。

请改用 `QMetaAssociation::Iterable::ConstIterator `。

QAssociativeIterable::const_iterator 允许在QVariant 中遍历容器。

QAssociativeIterable::const_iterator 只能由QAssociativeIterable 实例创建,其使用方式与其他 STL 风格的迭代器类似。

另请参阅 QAssociativeIterable 。

[alias, since 6.0, until 6.15] QAssociativeIterable::iterator

该 typedef 计划在 6.15 版本中被废弃。

请改用 `QMetaAssociation::Iterable::Iterator `。

QAssociativeIterable::iterator 允许在QVariant 中对容器进行迭代。

QAssociativeIterable::iterator 只能由QAssociativeIterable 实例创建,其使用方式与其他 STL 风格的迭代器类似。

此 typedef 于 Qt 6.0 中引入。

另请参阅 QAssociativeIterable 。

成员函数文档

bool QAssociativeIterable::containsKey(const QVariant &key)

如果容器中存在与给定key 匹配的条目,则返回true ;否则返回false 。如果key 无法转换为预期类型,则返回false 。

QAssociativeIterable::const_iterator QAssociativeIterable::find(const QVariant &key) const

获取一个指向给定key 处元素的const_iterator ,如果该键不存在,则返回容器的末尾。如果key 无法转换为预期类型,则返回容器的末尾。

void QAssociativeIterable::insertKey(const QVariant &key)

插入一个包含给定key 的新条目,或将任何现有条目中与给定key 对应的映射值重置为默认构造的映射值。key 将被强制转换为预期类型:如果无法转换,则插入默认值。

QAssociativeIterable::iterator QAssociativeIterable::mutableFind(const QVariant &key)

获取一个迭代器,该迭代器指向位于给定key 处的元素;如果该键不存在,则返回容器的末尾。如果key 无法转换为预期类型,则返回容器的末尾。

void QAssociativeIterable::removeKey(const QVariant &key)

从容器中移除具有给定key 的条目。key 将被强制转换为预期类型:如果无法转换,则移除其默认值。

void QAssociativeIterable::setValue(const QVariant &key, const QVariant &mapped)

将与key 关联的映射值设置为mapped (如果可能)。如果尚未存在,则为给定的key 插入一个新条目。如果key 无法转换为键的类型,则会覆盖默认构造的键类型的值。

另请参阅 value()。

QVariant QAssociativeIterable::value(const QVariant &key) const

获取位于指定key 处的映射值;如果该键不存在,则返回映射类型的默认构造的QVariant 。如果key 无法转换为键的类型,则返回与默认构造的键关联的映射值。

另请参阅 setValue()。

© 2026 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.