Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
QJSValueIterator Class Reference

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

#include <qjsvalueiterator.h>

+ Collaboration diagram for QJSValueIterator:

Public Member Functions

 QJSValueIterator (const QJSValue &value)
 Constructs an iterator for traversing object.
 
 ~QJSValueIterator ()
 Destroys the iterator.
 
bool hasNext () const
 Returns true if there is at least one item ahead of the iterator (i.e.
 
bool next ()
 Advances the iterator by one position.
 
QString name () const
 Returns the name of the last property that was jumped over using next().
 
QJSValue value () const
 Returns the value of the last property that was jumped over using next().
 
QJSValueIteratoroperator= (QJSValue &value)
 Makes the iterator operate on object.
 

Detailed Description

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

\inmodule QtQml

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:

...
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()) {
while (it.hasNext()) {
it.next();
qDebug() << it.name();
}
obj = obj.prototype();
}
See also
QJSValue::property()

Definition at line 17 of file qjsvalueiterator.h.

Constructor & Destructor Documentation

◆ QJSValueIterator()

QJSValueIterator::QJSValueIterator ( const QJSValue & object)

Constructs an iterator for traversing object.

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

Definition at line 93 of file qjsvalueiterator.cpp.

◆ ~QJSValueIterator()

QJSValueIterator::~QJSValueIterator ( )

Destroys the iterator.

Definition at line 101 of file qjsvalueiterator.cpp.

Member Function Documentation

◆ hasNext()

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.

See also
next()

Definition at line 112 of file qjsvalueiterator.cpp.

References QV4::PropertyKey::fromId(), QJSValueIteratorPrivate::isValid(), QJSValueIteratorPrivate::nextKey, and QV4::PersistentValue::value().

+ Here is the call graph for this function:

◆ name()

QString QJSValueIterator::name ( ) const

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

See also
value()

Definition at line 141 of file qjsvalueiterator.cpp.

References QJSValueIteratorPrivate::currentKey, QJSValueIteratorPrivate::engine, QV4::PropertyKey::fromId(), QJSValueIteratorPrivate::isValid(), Q_ASSERT, and QV4::PersistentValue::value().

+ Here is the call graph for this function:

◆ next()

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.

See also
hasNext(), name()

Definition at line 127 of file qjsvalueiterator.cpp.

References QJSValueIteratorPrivate::currentKey, QV4::PropertyKey::fromId(), QJSValueIteratorPrivate::isValid(), QJSValueIteratorPrivate::next(), and QV4::PersistentValue::value().

+ Here is the call graph for this function:

◆ operator=()

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

Definition at line 185 of file qjsvalueiterator.cpp.

References QJSValueIteratorPrivate::init().

+ Here is the call graph for this function:

◆ value()

QJSValue QJSValueIterator::value ( ) const

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

See also
name()

Definition at line 160 of file qjsvalueiterator.cpp.

References QV4::PersistentValue::asManaged(), QV4::ExecutionEngine::catchException(), QJSValueIteratorPrivate::currentKey, QJSValueIteratorPrivate::engine, QV4::Scope::engine, QV4::PropertyKey::fromId(), QJSValuePrivate::fromReturnedValue(), QV4::Scope::hasException(), QJSValueIteratorPrivate::isValid(), QJSValueIteratorPrivate::object, and QV4::PersistentValue::value().

+ Here is the call graph for this function:

The documentation for this class was generated from the following files: