在本页

QMetaAssociation::Iterable::ConstIterator Class

class QMetaAssociation::Iterable::ConstIterator

QMetaAssociation::Iterable::ConstIterator 允许迭代QVariant 中的容器 ... 更多...

该类在 Qt 6.11 中引入。

公共函数

QVariant key() const
QVariant value() const
QVariant operator*() const
int operator->() const

详细说明

QMetaAssociation::Iterable::ConstIterator 只能由QMetaAssociation::Iterable 实例创建,其使用方式与其他 stl 类型的迭代器类似。

QHash<intQString>mapping; mapping.insert(7, "Seven"); mapping.insert(11, "Eleven"); mapping.insert(42, "Forty-two");QVariant变量=QVariant::fromValue(mapping);if(variant.canConvert<QVariantHash>()) { QMetaAssociation::Iterable iterable=variant.value<QMetaAssociation::Iterable>();// 可以在值上使用 C++11 range-for: for(constQVariant&v: iterable) {        qDebug() << v;
    }// 可以使用迭代器QMetaAssociation::Iterable::const_iterator it=iterable.begin();constQMetaAssociation::Iterable::const_iterator end=iterable.end();for( ; it!=end;++it) {        qDebug() << *it; // The current value
        qDebug() << it.key();
        qDebug() << it.value();
    } }

另请参见 QMetaAssociation::Iterable

成员函数文档

QVariant ConstIterator::key() const

返回该迭代器指向的键值。

QVariant ConstIterator::value() const

返回该迭代器指向的映射值,如果没有映射值,则返回无效的QVariant

QVariant ConstIterator::operator*() const

返回当前项目,并转换为QVariant 。返回值是当前迭代器中的映射值(如果有的话),否则是键值。

int ConstIterator::operator->() const

返回当前项目,并转换为QVariant::ConstPointer 。如果当前迭代器中有映射值,QVariant::ConstPointer 将解析为映射值,否则将解析为键。

© 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.