Struct qt_core::QTemporaryDir

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

The QTemporaryDir class creates a unique directory for temporary use.

C++ class: QTemporaryDir.

C++ documentation:

The QTemporaryDir class creates a unique directory for temporary use.

QTemporaryDir is used to create unique temporary directories safely. The directory itself is created by the constructor. The name of the temporary directory is guaranteed to be unique (i.e., you are guaranteed to not overwrite an existing directory), and the directory will subsequently be removed upon destruction of the QTemporaryDir object. The directory name is either auto-generated, or created based on a template, which is passed to QTemporaryDir's constructor.

Example:

// Within a function/method…

QTemporaryDir dir; if (dir.isValid()) { // dir.path() returns the unique directory path }

// The QTemporaryDir destructor removes the temporary directory // as it goes out of scope.

It is very important to test that the temporary directory could be created, using isValid(). Do not use exists(), since a default-constructed QDir represents the current directory, which exists.

The path to the temporary directory can be found by calling path().

A temporary directory will have some static part of the name and some part that is calculated to be unique. The default path will be determined from QCoreApplication::applicationName() (otherwise qt_temp) and will be placed into the temporary path as returned by QDir::tempPath(). If you specify your own path, a relative path will not be placed in the temporary directory by default, but be relative to the current working directory. In all cases, a random string will be appended to the path in order to make it unique.

Implementations§

source§

impl QTemporaryDir

source

pub unsafe fn auto_remove(&self) -> bool

Returns true if the QTemporaryDir is in auto remove mode. Auto-remove mode will automatically delete the directory from disk upon destruction. This makes it very easy to create your QTemporaryDir object on the stack, fill it with files, do something with the files, and finally on function return it will automatically clean up after itself.

Calls C++ function: bool QTemporaryDir::autoRemove() const.

C++ documentation:

Returns true if the QTemporaryDir is in auto remove mode. Auto-remove mode will automatically delete the directory from disk upon destruction. This makes it very easy to create your QTemporaryDir object on the stack, fill it with files, do something with the files, and finally on function return it will automatically clean up after itself.

Auto-remove is on by default.

See also setAutoRemove() and remove().

source

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

If isValid() returns false, this function returns the error string that explains why the creation of the temporary directory failed. Otherwise, this function return an empty string.

Calls C++ function: QString QTemporaryDir::errorString() const.

C++ documentation:

If isValid() returns false, this function returns the error string that explains why the creation of the temporary directory failed. Otherwise, this function return an empty string.

This function was introduced in Qt 5.6.

source

pub unsafe fn file_path( &self, file_name: impl CastInto<Ref<QString>> ) -> CppBox<QString>

Returns the path name of a file in the temporary directory. Does not check if the file actually exists in the directory. Redundant multiple separators or "." and ".." directories in fileName are not removed (see QDir::cleanPath()). Absolute paths are not allowed.

Calls C++ function: QString QTemporaryDir::filePath(const QString& fileName) const.

C++ documentation:

Returns the path name of a file in the temporary directory. Does not check if the file actually exists in the directory. Redundant multiple separators or “.” and “..” directories in fileName are not removed (see QDir::cleanPath()). Absolute paths are not allowed.

This function was introduced in Qt 5.9.

source

pub unsafe fn is_valid(&self) -> bool

Returns true if the QTemporaryDir was created successfully.

Calls C++ function: bool QTemporaryDir::isValid() const.

C++ documentation:

Returns true if the QTemporaryDir was created successfully.

source

pub unsafe fn new_0a() -> CppBox<QTemporaryDir>

Constructs a QTemporaryDir using as template the application name returned by QCoreApplication::applicationName() (otherwise qt_temp). The directory is stored in the system's temporary directory, QDir::tempPath().

Calls C++ function: [constructor] void QTemporaryDir::QTemporaryDir().

C++ documentation:

Constructs a QTemporaryDir using as template the application name returned by QCoreApplication::applicationName() (otherwise qt_temp). The directory is stored in the system’s temporary directory, QDir::tempPath().

See also QDir::tempPath().

source

pub unsafe fn new_1a( template_name: impl CastInto<Ref<QString>> ) -> CppBox<QTemporaryDir>

Constructs a QTemporaryDir with a template of templatePath.

Calls C++ function: [constructor] void QTemporaryDir::QTemporaryDir(const QString& templateName).

C++ documentation:

Constructs a QTemporaryDir with a template of templatePath.

If templatePath is a relative path, the path will be relative to the current working directory. You can use QDir::tempPath() to construct templatePath if you want use the system's temporary directory.

If the templatePath ends with XXXXXX it will be used as the dynamic portion of the directory name, otherwise it will be appended. Unlike QTemporaryFile, XXXXXX in the middle of the template string is not supported.

See also QDir::tempPath().

source

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

Returns the path to the temporary directory. Empty if the QTemporaryDir could not be created.

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

C++ documentation:

Returns the path to the temporary directory. Empty if the QTemporaryDir could not be created.

source

pub unsafe fn remove(&self) -> bool

Removes the temporary directory, including all its contents.

Calls C++ function: bool QTemporaryDir::remove().

C++ documentation:

Removes the temporary directory, including all its contents.

Returns true if removing was successful.

source

pub unsafe fn set_auto_remove(&self, b: bool)

Sets the QTemporaryDir into auto-remove mode if b is true.

Calls C++ function: void QTemporaryDir::setAutoRemove(bool b).

C++ documentation:

Sets the QTemporaryDir into auto-remove mode if b is true.

Auto-remove is on by default.

See also autoRemove() and remove().

Trait Implementations§

source§

impl CppDeletable for QTemporaryDir

source§

unsafe fn delete(&self)

Destroys the temporary directory object. If auto remove mode was set, it will automatically delete the directory including all its contents.

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

C++ documentation:

Destroys the temporary directory object. If auto remove mode was set, it will automatically delete the directory including all its contents.

See also autoRemove().

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.