CopperSpice API  1.8.1
QAbstractFileEngineIterator Class Referenceabstract

The QAbstractFileEngineIterator class provides an iterator interface for custom file engines. More...

Public Methods

 QAbstractFileEngineIterator (QDir::Filters filters, const QStringList &nameFilters)
virtual ~QAbstractFileEngineIterator ()
virtual QFileInfo currentFileInfo () const
virtual QString currentFileName () const = 0
QString currentFilePath () const
QDir::Filters filters () const
virtual bool hasNext () const = 0
QStringList nameFilters () const
virtual QString next () = 0
QString path () const


class QDirIterator

Detailed Description

The QAbstractFileEngineIterator class provides an iterator interface for custom file engines. If your application only needs to iterate over entries in a directory then refer to QDirIterator. This class is used when implementing a custom file engine.

Example 1

The following three steps are required to use this class.

  • CustomFileEngineIterator must inherit from QAbstractFileEngineIterator
  • CustomFileEngine must inherit from QAbstractFileEngine
  • CustomFileEngine must override beginEntryList() and return a CustomFileEngineIterator
QAbstractFileEngineIterator * CustomFileEngine::beginEntryList(QDir::Filters filters, const QStringList &filterNames)
return new CustomFileEngineIterator(filters, filterNames);

Example 2

QAbstractFileEngineIterator is associated with a path, name filters, and entry filters. The path is the directory that the iterator lists entries in. The name filters and entry filters are provided for file engines that can optimize directory listing at the iterator level (e.g., network file systems that need to minimize network traffic), but they can also be ignored by the iterator subclass. QAbstractFileEngineIterator already provides the required filtering logics in the matchesFilters() function. You can call dirName() to get the directory name, nameFilters() to get a stringlist of name filters, and filters() to get the entry filters.

The methods hasNext() returns true if the current directory has at least one more entry and false otherwise. The method currentFileName() returns the name of the current entry without advancing the iterator. The currentFilePath() method returns the full path of the current entry.

The following example shows how to implement an iterator which returns each of three fixed entries in sequence.

class CustomIterator : public QAbstractFileEngineIterator
CustomIterator(const QStringList &nameFilters, QDir::Filters filters)
// In a real iterator, these entries are fetched from the
// file system based on the value of path().
entries << "entry1" << "entry2" << "entry3";
bool hasNext() const
return index < entries.size() - 1;
if (!hasNext()) {
return QString();
return currentFilePath();
QStringList entries;
int index;

QAbstractFileEngineIterator does not handle QDir::IteratorFlags it simply returns entries for a single directory.

See also

Constructor & Destructor Documentation

QAbstractFileEngineIterator::QAbstractFileEngineIterator ( QDir::Filters  filters,
const QStringList nameFilters 

Constructs a QAbstractFileEngineIterator using the entry filters and wildcard nameFilters.

QAbstractFileEngineIterator::~QAbstractFileEngineIterator ( )

Destroys the QAbstractFileEngineIterator.

See also

Method Documentation

QFileInfo QAbstractFileEngineIterator::currentFileInfo ( ) const

The virtual function returns a QFileInfo for the current directory entry. This function is provided for convenience. It can also be slightly faster than creating a QFileInfo object yourself, as the object returned by this function might contain cached information that QFileInfo otherwise would have to access through the file engine.

See also
QString QAbstractFileEngineIterator::currentFileName ( ) const
pure virtual

This pure virtual function returns the name of the current directory entry, excluding the path.

See also
QString QAbstractFileEngineIterator::currentFilePath ( ) const

Returns the path to the current directory entry. This is the same as prepending path() to the return value of currentFileName().

See also
QDir::Filters QAbstractFileEngineIterator::filters ( ) const

Returns the entry filters for this iterator.

See also
QDir::filter(), nameFilters(), path()
bool QAbstractFileEngineIterator::hasNext ( ) const
pure virtual

This pure virtual function returns true if there is at least one more entry in the current directory (i.e., the iterator path is valid and accessible, and the iterator has not reached the end of the entry list).

See also
QStringList QAbstractFileEngineIterator::nameFilters ( ) const

Returns the name filters for this iterator.

See also
QDir::nameFilters(), filters(), path()
QString QAbstractFileEngineIterator::next ( )
pure virtual

This pure virtual function advances the iterator to the next directory entry, and returns the file path to the current entry. This method can optionally make use of nameFilters() and filters() to optimize its performance.

When reimplementing this method make sure to advance the iterator.

See also
QString QAbstractFileEngineIterator::path ( ) const

Returns the path for this iterator.

See also
nameFilters(), filters()