Qt:Документация 4.3.2/qdiriterator

Материал из Wiki.crossplatform.ru

Перейти к: навигация, поиск
40px Внимание: Актуальная версия перевода документации находится здесь

__NOTOC__

Image:qt-logo.png

Главная · Все классы · Основные классы · Классы по группам · Модули · Функции

Image:trolltech-logo.png

Содержание

[править] QDirIterator Class Reference
[модуль QtCore ]

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

 #include <QDirIterator>

This class was introduced in Qt 4.3.

[править] Открытые типы

[править] Открытые функции

  • 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

[править] Подробное описание

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.


[править] Описание типов членов

[править]
enum QDirIterator::IteratorFlag
flags QDirIterator::IteratorFlags

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


Constant Value Description
QDirIterator::NoIteratorFlags 0x0 The default value, representing no flags. The iterator will return entries for the assigned path.
QDirIterator::Subdirectories 0x2 List entries inside all subdirectories as well.
QDirIterator::FollowSymlinks 0x1 When 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.


[править] Описание функций-членов

[править]
QDirIterator::QDirIterator ( const QDir & dir, IteratorFlags flags = NoIteratorFlags )

Constructs a QDirIterator that can iterate over dirs entrylist, using dirs 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.

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

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

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

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

[править]
QDirIterator::~QDirIterator () [virtual]

Destroys the QDirIterator.

[править]
QFileInfo QDirIterator::fileInfo () const

Returns a QFileInfo for the current directory entry. If the current entry is invalid (i.e., isValid() returns false), a null QFileInfo is returned.

See also filePath() and fileName().

[править]
QString QDirIterator::fileName () const

Returns the file name for the current directory entry, without the path prepended. If the current entry is invalid (i.e., isValid() returns false), a null QString is returned.

This function is provided for the convenience when iterating single directories. For recursive iteration, you should call filePath() or fileInfo() instead.

See also filePath() and fileInfo().

[править]
QString QDirIterator::filePath () const

Returns the full file path for the current directory entry. If the current entry is invalid (i.e., isValid() returns false), a null QString is returned.

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.


Copyright © 2007 Trolltech Trademarks
Qt 4.3.2