Skip to content

PythonQt.QtCore.QTemporaryDir

QTemporaryDir

PythonQtInstanceWrapper object

Native bases: PythonQtInstanceWrapper

Supplemental documentation: Qt 5 reference:

Detailed Description

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.

Source: https://doc.qt.io/archives/qt-5.15/qtemporarydir.html

Complete member index

Every captured member retains its own identity. Identical captured declaration text is linked once; this does not establish native inheritance or interchangeable objects.

Member Kind Signature Summary
__init__ function (self, *args: Any, **kwargs: Any) -> None Native constructor; consult class documentation for supported overloads. (shared captured text)
autoRemove function (self) -> bool X.autoRemove() -> bool
className function (self, *args: Any, **kwargs: Any) -> Any Return the classname of the object (shared captured text)
delete function (self, *args: Any, **kwargs: Any) -> Any Deletes the C++ object (at your own risk, my friend!) (shared captured text)
errorString function (self) -> str X.errorString() -> str
help function (self, *args: Any, **kwargs: Any) -> Any Shows the help of available methods for this class (shared captured text)
inherits function (self, *args: Any, **kwargs: Any) -> Any Returns if the class inherits or is of given type name (shared captured text)
isValid function (self) -> bool X.isValid() -> bool
path function (self) -> str X.path() -> str
remove function (self) -> bool X.remove() -> bool
setAutoRemove function (self, b: bool) -> None Sets the [QTemporaryDir](https://doc.qt.io/archives/qt-5.15/qtemporarydir.html) into auto-remove mode if b is true.