QScriptValueIterator Class

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

头: #include <QScriptValueIterator>
qmake: QT += script
Since: Qt 4.3

该类在 Qt 4.3 引入。

公共函数

QScriptValueIterator (const QScriptValue & object )
QScriptValueIterator & operator= (QScriptValue & object )
~QScriptValueIterator ()
QScriptValue::PropertyFlags flags () const
bool hasNext () const
bool hasPrevious () const
QString name () const
void next ()
void previous ()
void remove ()
QScriptString scriptName () const
void setValue (const QScriptValue & value )
void toBack ()
void toFront ()
QScriptValue value () const

详细描述

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 :

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

The next () advances the iterator. The name (), value () 和 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 ,使用 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:

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

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:

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

另请参阅 QScriptValue::property ().

成员函数文档编制

QScriptValueIterator:: QScriptValueIterator (const QScriptValue & object )

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

QScriptValueIterator &QScriptValueIterator:: operator= ( 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).

QScriptValueIterator:: ~QScriptValueIterator ()

销毁迭代器。

QScriptValue::PropertyFlags QScriptValueIterator:: flags () const

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

另请参阅 value ().

bool QScriptValueIterator:: 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 () 和 hasPrevious ().

bool QScriptValueIterator:: hasPrevious () 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.

另请参阅 previous () 和 hasNext ().

QString QScriptValueIterator:: name () const

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

另请参阅 value () 和 flags ().

void QScriptValueIterator:: next ()

Advances the iterator by one position.

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

另请参阅 hasNext (), previous (),和 name ().

void QScriptValueIterator:: previous ()

Moves the iterator back by one position.

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

另请参阅 hasPrevious (), next (),和 name ().

void QScriptValueIterator:: remove ()

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

另请参阅 setValue ().

QScriptString QScriptValueIterator:: scriptName () const

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

该函数在 Qt 4.4 引入。

void QScriptValueIterator:: setValue (const QScriptValue & value )

设置 value of the last property that was jumped over using next () 或 previous ().

另请参阅 value () 和 name ().

void QScriptValueIterator:: toBack ()

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

另请参阅 toFront () 和 previous ().

void QScriptValueIterator:: toFront ()

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

另请参阅 toBack () 和 next ().

QScriptValue QScriptValueIterator:: value () const

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

另请参阅 setValue () 和 name ().