QScriptValueIterator Class Reference

The QScriptValueIterator class provides a Java-style iterator for QScriptValue.

  1. #include <QScriptValueIterator>

This class was introduced in Qt 4.3.

Detailed Description

The QScriptValueIterator class provides a Java-style iterator for QScriptValue.

The QScriptValueIterator constructor takes a QScriptValue 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 QScriptValue:

  1.                 QScriptValue object;
  2. ...
  3. while (it.hasNext())  {
  4.     it.next();
  5.     qDebug() << it.name() << ": " << it.value().toString();
  6. }

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

If you want to remove properties as you iterate over the QScriptValue, use remove(). If you want to modify the value of a property, use setValue().

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

  1.                 QScriptValue obj = ...; // the object to iterate over
  2. while (obj.isObject())  {
  3.     QScriptValueIterator it(obj);
  4.     while (it.hasNext())  {
  5.         it.next();
  6.         qDebug() << it.name();
  7.     }
  8.     obj = obj.prototype();
  9. }

Note that QScriptValueIterator will not automatically skip over properties that have the QScriptValue::SkipInEnumeration flag set; that flag only affects iteration in script code. If you want, you can skip over such properties with code like the following:

  1. while (it.hasNext())  {
  2.     it.next();
  3.     if (it.flags() & QScriptValue::SkipInEnumeration)
  4.         continue;
  5.     qDebug() << "found enumerated property:" << it.name();
  6. }

See also QScriptValue::property().

Public Functions

Toggle details QScriptValueIterator

QScriptValueIteratorQScriptValueIterator ( const QScriptValue &object ) ( const QScriptValue &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).

Look up this member in the source code.

Toggle details QScriptValueIterator

~QScriptValueIterator~QScriptValueIterator () ()

Destroys the iterator.

Look up this member in the source code.

Toggle details QScriptValue::PropertyFlags QScriptValueIterator

flagsflags () ()const

Returns the flags of the last property that was jumped over using next() or previous().

See also value().

Look up this member in the source code.

Toggle details bool QScriptValueIterator

hasNexthasNext () ()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() and hasPrevious().

Look up this member in the source code.

Toggle details bool QScriptValueIterator

hasPrevioushasPrevious () ()const

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

See also previous() and hasNext().

Look up this member in the source code.

Toggle details QString QScriptValueIterator

namename () ()const

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

See also value() and flags().

Look up this member in the source code.

Toggle details void QScriptValueIterator

nextnext () ()

Advances the iterator by one position.

Calling this function on an iterator located at the back of the container leads to undefined results.

See also hasNext(), previous(), and name().

Look up this member in the source code.

Toggle details void QScriptValueIterator

previousprevious () ()

Moves the iterator back by one position.

Calling this function on an iterator located at the front of the container leads to undefined results.

See also hasPrevious(), next(), and name().

Look up this member in the source code.

Toggle details void QScriptValueIterator

removeremove () ()

Removes the last property that was jumped over using next() or previous().

See also setValue().

Look up this member in the source code.

Toggle details QScriptString QScriptValueIterator

scriptNamescriptName () ()const

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

Look up this member in the source code.

Toggle details void QScriptValueIterator

setValuesetValue ( const QScriptValue &value ) ( const QScriptValue &value )

Sets the value of the last property that was jumped over using next() or previous().

See also value() and name().

Look up this member in the source code.

Toggle details void QScriptValueIterator

toBacktoBack () ()

Moves the iterator to the back of the QScriptValue (after the last property).

See also toFront() and previous().

Look up this member in the source code.

Toggle details void QScriptValueIterator

toFronttoFront () ()

Moves the iterator to the front of the QScriptValue (before the first property).

See also toBack() and next().

Look up this member in the source code.

Toggle details QScriptValue QScriptValueIterator

valuevalue () ()const

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

See also setValue() and name().

Look up this member in the source code.

Toggle details QScriptValueIterator & QScriptValueIterator

operator=operator= ( QScriptValue &object ...) ( QScriptValue &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).

Look up this member in the source code.

    Notes provided by the Qt Community

    No notes