In questa pagina

QMetaAssociation::Iterable::ConstIterator Class

class QMetaAssociation::Iterable::ConstIterator

QMetaAssociation::Iterable::ConstIterator consente di eseguire un'iterazione su un contenitore in un ciclo " QVariant". Altro...

Questa classe è stata introdotta in Qt 6.11.

Funzioni pubbliche

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

Descrizione dettagliata

Un oggetto ` QMetaAssociation::Iterable::ConstIterator ` può essere creato solo da un'istanza di ` QMetaAssociation::Iterable ` e può essere utilizzato in modo simile agli altri iteratori in stile STL.

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>()) {
    QMetaAssociation::Iterable iterable = variant.value<QMetaAssociation::Iterable>();
    // È possibile utilizzare il ciclo range-for di C++11 sui valori:
    for (const QVariant&v: iterable) {
        qDebug() << v;
    }
    // È possibile utilizzare gli iteratori:
    QMetaAssociation::Iterable::const_iteratorit = iterable.begin();
    const QMetaAssociation::Iterable::const_iteratorend = iterable.end();
    for ( ; it != end;++it) {
        qDebug() << *it; // The current value
        qDebug() << it.key();
        qDebug() << it.value();
    }
}

Vedi anche QMetaAssociation::Iterable.

Documentazione sulle funzioni membro

QVariant ConstIterator::key() const

Restituisce la chiave a cui punta questo iteratore.

QVariant ConstIterator::value() const

Restituisce il valore mappato a cui punta questo iteratore oppure un oggetto ` QVariant ` non valido se non esiste alcun valore mappato.

QVariant ConstIterator::operator*() const

Restituisce l'elemento corrente, convertito in un oggetto ` QVariant`. Il valore restituito è il valore mappato all'iteratore corrente, se presente, oppure, in caso contrario, la chiave.

int ConstIterator::operator->() const

Restituisce l'elemento corrente, convertito in un oggetto ` QVariant::ConstPointer`. L'oggetto ` QVariant::ConstPointer ` verrà risolto nel valore mappato all'iteratore corrente, se presente, oppure, in caso contrario, nella chiave.

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