Viadeo Twitter Google Bookmarks ! Facebook Digg del.icio.us MySpace Yahoo MyWeb Blinklist Netvouz Reddit Simpy StumbleUpon Bookmarks Windows Live Favorites 
Logo Documentation Qt ·  Page d'accueil  ·  Toutes les classes  ·  Toutes les fonctions  ·  Vues d'ensemble  · 

QScriptValueIterator Class Reference
[QtScript module]

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

 #include <QScriptValueIterator>

This class is not part of the Qt GUI Framework Edition.

This class was introduced in Qt 4.3.


Public Functions

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

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:

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

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:

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

See also QScriptValue::property().


Member Function Documentation

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

QScriptValueIterator::~QScriptValueIterator ()

Destroys the iterator.

QScriptValue::PropertyFlags QScriptValueIterator::flags () const

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

See also 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.

See also next() and 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.

See also previous() and hasNext().

QString QScriptValueIterator::name () const

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

See also value() and 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.

See also hasNext(), previous(), and 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.

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

void QScriptValueIterator::remove ()

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

See also setValue().

QScriptString QScriptValueIterator::scriptName () const

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

This function was introduced in Qt 4.4.

void QScriptValueIterator::setValue ( const QScriptValue & value )

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

See also value() and name().

void QScriptValueIterator::toBack ()

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

See also toFront() and previous().

void QScriptValueIterator::toFront ()

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

See also toBack() and next().

QScriptValue QScriptValueIterator::value () const

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

See also setValue() and name().

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

Publicité

Best Of

Actualités les plus lues

Semaine
Mois
Année
  1. « Quelque chose ne va vraiment pas avec les développeurs "modernes" », un développeur à "l'ancienne" critique la multiplication des bibliothèques 80
  2. Apercevoir la troisième dimension ou l'utilisation multithreadée d'OpenGL dans Qt, un article des Qt Quarterly traduit par Guillaume Belz 0
  3. Les développeurs ignorent-ils trop les failles découvertes dans leur code ? Prenez-vous en compte les remarques des autres ? 17
  4. BlackBerry 10 : premières images du prochain OS de RIM qui devrait intégrer des widgets et des tuiles inspirées de Windows Phone 0
  5. Quelles nouveautés de C++11 Visual C++ doit-il rapidement intégrer ? Donnez-nous votre avis 10
  6. Adieu qmake, bienvenue qbs : Qt Building Suite, un outil déclaratif et extensible pour la compilation de projets Qt 17
  7. 2017 : un quinquennat pour une nouvelle version du C++ ? Possible, selon Herb Sutter 6
Page suivante

Le Qt Developer Network au hasard

Logo

Combiner licence, à propos et fermer d'une dernière manière

Le Qt Developer Network est un réseau de développeurs Qt anglophone, où ils peuvent partager leur expérience sur le framework. Lire l'article.

Communauté

Ressources

Liens utiles

Contact

  • Vous souhaitez rejoindre la rédaction ou proposer un tutoriel, une traduction, une question... ? Postez dans le forum Contribuez ou contactez-nous par MP ou par email (voir en bas de page).

Qt dans le magazine

Cette page est une traduction d'une page de la documentation de Qt, écrite par Nokia Corporation and/or its subsidiary(-ies). Les éventuels problèmes résultant d'une mauvaise traduction ne sont pas imputables à Nokia. Qt 4.6
Copyright © 2012 Developpez LLC. Tous droits réservés Developpez LLC. Aucune reproduction, même partielle, ne peut être faite de ce site et de l'ensemble de son contenu : textes, documents et images sans l'autorisation expresse de Developpez LLC. Sinon, vous encourez selon la loi jusqu'à 3 ans de prison et jusqu'à 300 000 E de dommages et intérêts. Cette page est déposée à la SACD.
Vous avez déniché une erreur ? Un bug ? Une redirection cassée ? Ou tout autre problème, quel qu'il soit ? Ou bien vous désirez participer à ce projet de traduction ? N'hésitez pas à nous contacter ou par MP !
 
 
 
 
Partenaires

Hébergement Web