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  · 

QDirIterator Class Reference

The QDirIterator class provides an iterator for directory entrylists. More...

 #include <QDirIterator>

This class was introduced in Qt 4.3.

Public Types

enum IteratorFlag { NoIteratorFlags, Subdirectories, FollowSymlinks }
flags IteratorFlags

Public Functions

QDirIterator ( const QDir & dir, IteratorFlags flags = NoIteratorFlags )
QDirIterator ( const QString & path, IteratorFlags flags = NoIteratorFlags )
QDirIterator ( const QString & path, QDir::Filters filters, IteratorFlags flags = NoIteratorFlags )
QDirIterator ( const QString & path, const QStringList & nameFilters, QDir::Filters filters = QDir::NoFilter, IteratorFlags flags = NoIteratorFlags )
virtual ~QDirIterator ()
QFileInfo fileInfo () const
QString fileName () const
QString filePath () const
bool hasNext () const
QString next ()
QString path () const

Detailed Description

The QDirIterator class provides an iterator for directory entrylists.

You can use QDirIterator to navigate entries of a directory one at a time. It is similar to QDir::entryList() and QDir::entryInfoList(), but because it lists entries one at a time instead of all at once, it scales better and is more suitable for large directories. It also supports listing directory contents recursively, and following symbolic links. Unlike QDir::entryList(), QDirIterator does not support sorting.

The QDirIterator constructor takes a QDir or a directory as argument. After construction, the iterator is located before the first directory entry. Here's how to iterate over all the entries sequentially:

 QDirIterator it("/etc", QDirIterator::Subdirectories);
 while (it.hasNext()) {
     qDebug() << it.next();

     // /etc/.
     // /etc/..
     // /etc/X11
     // /etc/X11/fs
     // ...
 }

The next() function returns the path to the next directory entry and advances the iterator. You can also call filePath() to get the current file path without advancing the iterator. The fileName() function returns only the name of the file, similar to how QDir::entryList() works. You can also call fileInfo() to get a QFileInfo for the current entry.

Unlike Qt's container iterators, QDirIterator is uni-directional (i.e., you cannot iterate directories in reverse order) and does not allow random access.

QDirIterator works with all supported file engines, and is implemented using QAbstractFileEngineIterator.

See also QDir, QDir::entryList(), and QAbstractFileEngineIterator.

Member Type Documentation

enum QDirIterator::IteratorFlag
flags QDirIterator::IteratorFlags

This enum describes flags that you can combine to configure the behavior of QDirIterator.

ConstantValueDescription
QDirIterator::NoIteratorFlags0x0The default value, representing no flags. The iterator will return entries for the assigned path.
QDirIterator::Subdirectories0x2List entries inside all subdirectories as well.
QDirIterator::FollowSymlinks0x1When combined with Subdirectories, this flag enables iterating through all subdirectories of the assigned path, following all symbolic links. Symbolic link loops (e.g., "link" => "." or "link" => "..") are automatically detected and ignored.

The IteratorFlags type is a typedef for QFlags<IteratorFlag>. It stores an OR combination of IteratorFlag values.

Member Function Documentation

QDirIterator::QDirIterator ( const QDir & dir, IteratorFlags flags = NoIteratorFlags )

Constructs a QDirIterator that can iterate over dir's entrylist, using dir's name filters and regular filters. You can pass options via flags to decide how the directory should be iterated.

By default, flags is NoIteratorFlags, which provides the same behavior as in QDir::entryList().

The sorting in dir is ignored.

Note: To list symlinks that point to non existing files, QDir::System must be passed to the flags.

See also hasNext(), next(), and IteratorFlags.

QDirIterator::QDirIterator ( const QString & path, IteratorFlags flags = NoIteratorFlags )

Constructs a QDirIterator that can iterate over path. You can pass options via flags to decide how the directory should be iterated.

By default, flags is NoIteratorFlags, which provides the same behavior as in QDir::entryList().

Note: To list symlinks that point to non existing files, QDir::System must be passed to the flags.

See also hasNext(), next(), and IteratorFlags.

QDirIterator::QDirIterator ( const QString & path, QDir::Filters filters, IteratorFlags flags = NoIteratorFlags )

Constructs a QDirIterator that can iterate over path, with no name filtering and filters for entry filtering. You can pass options via flags to decide how the directory should be iterated.

By default, filters is QDir::NoFilter, and flags is NoIteratorFlags, which provides the same behavior as in QDir::entryList().

Note: To list symlinks that point to non existing files, QDir::System must be passed to the flags.

See also hasNext(), next(), and IteratorFlags.

QDirIterator::QDirIterator ( const QString & path, const QStringList & nameFilters, QDir::Filters filters = QDir::NoFilter, IteratorFlags flags = NoIteratorFlags )

Constructs a QDirIterator that can iterate over path, using nameFilters and filters. You can pass options via flags to decide how the directory should be iterated.

By default, flags is NoIteratorFlags, which provides the same behavior as QDir::entryList().

Note: To list symlinks that point to non existing files, QDir::System must be passed to the flags.

See also hasNext(), next(), and IteratorFlags.

QDirIterator::~QDirIterator () [virtual]

Destroys the QDirIterator.

QFileInfo QDirIterator::fileInfo () const

Returns a QFileInfo for the current directory entry.

See also filePath() and fileName().

QString QDirIterator::fileName () const

Returns the file name for the current directory entry, without the path prepended.

This function is convenient when iterating a single directory. When using the QDirIterator::Subdirectories flag, you can use filePath() to get the full path.

See also filePath() and fileInfo().

QString QDirIterator::filePath () const

Returns the full file path for the current directory entry.

See also fileInfo() and fileName().

bool QDirIterator::hasNext () const

Returns true if there is at least one more entry in the directory; otherwise, false is returned.

See also next(), fileName(), filePath(), and fileInfo().

QString QDirIterator::next ()

Advances the iterator to the next entry, and returns the file path of this new entry. If hasNext() returns false, this function does nothing, and returns a null QString.

You can call fileName() or filePath() to get the current entry file name or path, or fileInfo() to get a QFileInfo for the current entry.

See also hasNext(), fileName(), filePath(), and fileInfo().

QString QDirIterator::path () const

Returns the base directory of the iterator.

Publicité

Best Of

Actualités les plus lues

Semaine
Mois
Année
  1. Microsoft ouvre aux autres compilateurs C++ AMP, la spécification pour la conception d'applications parallèles C++ utilisant le GPU 22
  2. Les développeurs ignorent-ils trop les failles découvertes dans leur code ? Prenez-vous en compte les remarques des autres ? 17
  3. RIM : « 13 % des développeurs ont gagné plus de 100 000 $ sur l'AppWord », Qt et open-source au menu du BlackBerry DevCon Europe 0
  4. « Quelque chose ne va vraiment pas avec les développeurs "modernes" », un développeur à "l'ancienne" critique la multiplication des bibliothèques 12
  5. 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
  6. Adieu qmake, bienvenue qbs : Qt Building Suite, un outil déclaratif et extensible pour la compilation de projets Qt 17
  7. Quelles nouveautés de C++11 Visual C++ doit-il rapidement intégrer ? Donnez-nous votre avis 10
Page suivante

Le Qt Developer Network au hasard

Logo

Compiler l'add-in Qt de Visual Studio

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