![]() |
Qt 6.x
The Qt SDK
|
The QJSValueIterator class provides a Java-style iterator for QJSValue. More...
#include <qjsvalueiterator.h>
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(). | |
QJSValueIterator & | operator= (QJSValue &value) |
Makes the iterator operate on object. | |
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:
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:
Definition at line 17 of file qjsvalueiterator.h.
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 | ( | ) |
Destroys the iterator.
Definition at line 101 of file qjsvalueiterator.cpp.
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.
Definition at line 112 of file qjsvalueiterator.cpp.
References QV4::PropertyKey::fromId(), QJSValueIteratorPrivate::isValid(), QV4::PropertyKey::isValid(), QJSValueIteratorPrivate::nextKey, and QV4::PersistentValue::value().
QString QJSValueIterator::name | ( | ) | const |
Returns the name of the last property that was jumped over using next().
Definition at line 141 of file qjsvalueiterator.cpp.
References QJSValueIteratorPrivate::currentKey, QJSValueIteratorPrivate::engine, QV4::PropertyKey::fromId(), QJSValueIteratorPrivate::isValid(), Q_ASSERT, and QV4::PersistentValue::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.
Definition at line 127 of file qjsvalueiterator.cpp.
References QJSValueIteratorPrivate::currentKey, QV4::PropertyKey::fromId(), QJSValueIteratorPrivate::isValid(), QV4::PropertyKey::isValid(), QJSValueIteratorPrivate::next(), and QV4::PersistentValue::value().
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().
QJSValue QJSValueIterator::value | ( | ) | const |
Returns the value of the last property that was jumped over using next().
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().