QJSValueIterator Class

The QJSValueIterator class provides a Java-style iterator for QJSValue. More...

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

Detailed Description

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() and 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();
 }

See also QJSValue::property().