QJSValueIterator 類

QJSValueIterator 類提供 Java 樣式迭代器為 QJSValue . 更多...

頭: #include <QJSValueIterator>
qmake: QT += qml

公共函數

QJSValueIterator (const QJSValue & object )
QJSValueIterator & operator= (QJSValue & object )
~QJSValueIterator ()
bool hasNext () const
QString name () const
bool next ()
QJSValue value () const

詳細描述

The QJSValueIterator constructor takes a QJSValue as argument. After construction, the iterator is located at the very beginning of the sequence of properties. Here's how to iterate over all the properties of a QJSValue :

QJSValue object;
...
QJSValueIterator it(object);
while (it.hasNext()) {
    it.next();
    qDebug() << it.name() << ": " << it.value().toString();
}
					

The next () advances the iterator. The name () 和 value () functions return the name and value of the last item that was jumped over.

Note that QJSValueIterator only iterates over the QJSValue 's own properties; i.e. it does not follow the prototype chain. You can use a loop like this to follow the prototype chain:

QJSValue obj = ...; // the object to iterate over
while (obj.isObject()) {
    QJSValueIterator it(obj);
    while (it.hasNext()) {
        it.next();
        qDebug() << it.name();
    }
    obj = obj.prototype();
}
					

另請參閱 QJSValue::property ().

成員函數文檔編製

QJSValueIterator:: QJSValueIterator (const QJSValue & object )

構造迭代器為遍曆 object . The iterator is set to be at the front of the sequence of properties (before the first property).

QJSValueIterator &QJSValueIterator:: operator= ( QJSValue & object )

Makes the iterator operate on object . The iterator is set to be at the front of the sequence of properties (before the first property).

QJSValueIterator:: ~QJSValueIterator ()

銷毀迭代器。

bool QJSValueIterator:: hasNext () const

Returns true if there is at least one item ahead of the iterator (i.e. the iterator is not at the back of the property sequence); otherwise returns false.

另請參閱 next ().

QString QJSValueIterator:: name () const

Returns the name of the last property that was jumped over using next ().

另請參閱 value ().

bool QJSValueIterator:: next ()

Advances the iterator by one position. Returns true if there was at least one item ahead of the iterator (i.e. the iterator was not already at the back of the property sequence); otherwise returns false.

另請參閱 hasNext () 和 name ().

QJSValue QJSValueIterator:: value () const

Returns the value of the last property that was jumped over using next ().

另請參閱 name ().