QAssociativeIterable Class
QAssociativeIterableクラスは、QVariant の連想コンテナのイテレート・インターフェイスです。
ヘッダー | #include <QAssociativeIterable> |
CMake: | find_package(Qt6 REQUIRED COMPONENTS Core) target_link_libraries(mytarget PRIVATE Qt6::Core) |
qmake: | QT += core |
を継承する: | QIterable |
パブリックタイプ
パブリック関数
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 のインスタンスは、QVariantHash またはQVariantMap に変換できる場合、またはカスタムミュータブルビューが登録されている場合、QVariant から抽出することができます。
QHash<int、 QString> mapping; mapping.insert(7, "Seven"); mapping.insert(11, "Eleven"); mapping.insert(42, "Forty-two");QVariantvariant=QVariant::fromValue(mapping);if(variant.canConvert<QVariantHash>()) {QAssociativeIterableiterable=variant.value<QAssociativeIterable>();// foreach を値の上で使うことができる:foreach(constQVariantforeach (const v,iterable) { // 値に対して foreach を使うことができます。 qDebug() << v; }// C++11 の range-for を値に対して使用できる: for(constQVariant&v: iterable) { の場合 qDebug() << v; 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
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]
QAssociativeIterable::const_iterator
QAssociativeIterable::const_iterator は、QVariant のコンテナに対する反復処理を可能にします。
QAssociativeIterable::const_iterator は、QAssociativeIterable インスタンスによってのみ作成でき、他の stl 形式のイテレータと同様の方法で使用できます。
QHash<int、 QString> mapping; mapping.insert(7, "Seven"); mapping.insert(11, "Eleven"); mapping.insert(42, "Forty-two");QVariantvariant=QVariant::fromValue(mapping);if(variant.canConvert<QVariantHash>()) {QAssociativeIterableiterable=variant.value<QAssociativeIterable>();// foreach を値の上で使うことができる:foreach(constQVariantforeach (const v,iterable) { // 値に対して foreach を使うことができます。 qDebug() << v; }// C++11 の range-for を値に対して使用できる: for(constQVariant&v: iterable) { の場合 qDebug() << v; 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
QAssociativeIterable::iterator は、QVariant のコンテナに対する反復処理を可能にします。
QAssociativeIterable::iterator は、QAssociativeIterable インスタンスによってのみ作成でき、他の stl スタイルのイテレータと同様の方法で使用できる。
この型定義は 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()も参照のこと 。
© 2025 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.