Struct qt_core::QDirIterator

source ·
#[repr(C)]
pub struct QDirIterator { /* private fields */ }
Expand description

The QDirIterator class provides an iterator for directory entrylists.

C++ class: QDirIterator.

C++ documentation:

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 // … }

Here's how to find and read all files filtered by name, recursively:

QDirIterator it(“/sys”, QStringList() << “scaling_cur_freq”, QDir::NoFilter, QDirIterator::Subdirectories); while (it.hasNext()) { QFile f(it.next()); f.open(QIODevice::ReadOnly); qDebug() << f.fileName() << f.readAll().trimmed().toDouble() / 1000 << “MHz”; }

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.

Implementations§

source§

impl QDirIterator

source

pub unsafe fn file_info(&self) -> CppBox<QFileInfo>

Returns a QFileInfo for the current directory entry.

Calls C++ function: QFileInfo QDirIterator::fileInfo() const.

C++ documentation:

Returns a QFileInfo for the current directory entry.

See also filePath() and fileName().

source

pub unsafe fn file_name(&self) -> CppBox<QString>

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

Calls C++ function: QString QDirIterator::fileName() const.

C++ documentation:

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

source

pub unsafe fn file_path(&self) -> CppBox<QString>

Returns the full file path for the current directory entry.

Calls C++ function: QString QDirIterator::filePath() const.

C++ documentation:

Returns the full file path for the current directory entry.

See also fileInfo() and fileName().

source

pub unsafe fn has_next(&self) -> bool

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

Calls C++ function: bool QDirIterator::hasNext() const.

C++ documentation:

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

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

source

pub unsafe fn from_q_dir_q_flags_iterator_flag( dir: impl CastInto<Ref<QDir>>, flags: QFlags<IteratorFlag> ) -> CppBox<QDirIterator>

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.

Calls C++ function: [constructor] void QDirIterator::QDirIterator(const QDir& dir, QFlags<QDirIterator::IteratorFlag> flags = …).

C++ documentation:

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.

source

pub unsafe fn from_q_string_q_flags_iterator_flag( path: impl CastInto<Ref<QString>>, flags: QFlags<IteratorFlag> ) -> CppBox<QDirIterator>

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

Calls C++ function: [constructor] void QDirIterator::QDirIterator(const QString& path, QFlags<QDirIterator::IteratorFlag> flags = …).

C++ documentation:

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.

source

pub unsafe fn from_q_string_q_flags_filter_q_flags_iterator_flag( path: impl CastInto<Ref<QString>>, filter: QFlags<Filter>, flags: QFlags<IteratorFlag> ) -> CppBox<QDirIterator>

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.

Calls C++ function: [constructor] void QDirIterator::QDirIterator(const QString& path, QFlags<QDir::Filter> filter, QFlags<QDirIterator::IteratorFlag> flags = …).

C++ documentation:

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.

source

pub unsafe fn from_q_string_q_string_list_q_flags_filter_q_flags_iterator_flag( path: impl CastInto<Ref<QString>>, name_filters: impl CastInto<Ref<QStringList>>, filters: QFlags<Filter>, flags: QFlags<IteratorFlag> ) -> CppBox<QDirIterator>

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.

Calls C++ function: [constructor] void QDirIterator::QDirIterator(const QString& path, const QStringList& nameFilters, QFlags<QDir::Filter> filters = …, QFlags<QDirIterator::IteratorFlag> flags = …).

C++ documentation:

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.

source

pub unsafe fn from_q_dir(dir: impl CastInto<Ref<QDir>>) -> CppBox<QDirIterator>

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.

Calls C++ function: [constructor] void QDirIterator::QDirIterator(const QDir& dir).

C++ documentation:

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.

source

pub unsafe fn from_q_string( path: impl CastInto<Ref<QString>> ) -> CppBox<QDirIterator>

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

Calls C++ function: [constructor] void QDirIterator::QDirIterator(const QString& path).

C++ documentation:

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.

source

pub unsafe fn from_q_string_q_flags_filter( path: impl CastInto<Ref<QString>>, filter: QFlags<Filter> ) -> CppBox<QDirIterator>

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.

Calls C++ function: [constructor] void QDirIterator::QDirIterator(const QString& path, QFlags<QDir::Filter> filter).

C++ documentation:

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.

source

pub unsafe fn from_q_string_q_string_list_q_flags_filter( path: impl CastInto<Ref<QString>>, name_filters: impl CastInto<Ref<QStringList>>, filters: QFlags<Filter> ) -> CppBox<QDirIterator>

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.

Calls C++ function: [constructor] void QDirIterator::QDirIterator(const QString& path, const QStringList& nameFilters, QFlags<QDir::Filter> filters = …).

C++ documentation:

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.

source

pub unsafe fn from_q_string_q_string_list( path: impl CastInto<Ref<QString>>, name_filters: impl CastInto<Ref<QStringList>> ) -> CppBox<QDirIterator>

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.

Calls C++ function: [constructor] void QDirIterator::QDirIterator(const QString& path, const QStringList& nameFilters).

C++ documentation:

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.

source

pub unsafe fn next(&self) -> CppBox<QString>

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 an empty QString.

Calls C++ function: QString QDirIterator::next().

C++ documentation:

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

source

pub unsafe fn path(&self) -> CppBox<QString>

Returns the base directory of the iterator.

Calls C++ function: QString QDirIterator::path() const.

C++ documentation:

Returns the base directory of the iterator.

Trait Implementations§

source§

impl CppDeletable for QDirIterator

source§

unsafe fn delete(&self)

Destroys the QDirIterator.

Calls C++ function: [destructor] void QDirIterator::~QDirIterator().

C++ documentation:

Destroys the QDirIterator.

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T, U> CastInto<U> for T
where U: CastFrom<T>,

source§

unsafe fn cast_into(self) -> U

Performs the conversion. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> StaticUpcast<T> for T

source§

unsafe fn static_upcast(ptr: Ptr<T>) -> Ptr<T>

Convert type of a const pointer. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.