Search for usage in LXR

#include <KTempDir>

Public Member Functions

 KTempDir (const QString &directoryPrefix=QString(), int mode=0700)
 ~KTempDir ()
bool autoRemove () const
bool exists () const
QString name () const
void setAutoRemove (bool autoRemove)
int status () const
void unlink ()

Static Public Member Functions

static bool removeDir (const QString &path)

Protected Member Functions

bool create (const QString &directoryPrefix, int mode)

Detailed Description

Create a unique directory for temporary use.

use QTemporaryDir

The KTempDir class creates a unique directory for temporary use.

Porting to QTemporaryDir goes as follows:

A typical usage of KTempDir was KTempDir(KStandardDirs::locateLocal("tmp", prefix)); This should be ported to QTemporaryDir(QDir::tempPath() + QLatin1Char('/') + prefix);

Note: KTempDir does not create any missing directories, but KStandardDirs::locateLocal() does.

See also

Definition at line 50 of file ktempdir.h.

Constructor & Destructor Documentation

◆ KTempDir()

KTempDir::KTempDir ( const QString directoryPrefix = QString(),
int  mode = 0700 

Creates a temporary directory with the name: <directoryPrefix><six letters>

The default directoryPrefix is "/tmp/appname"

directoryPrefixthe prefix of the file name, or QString() for the default value
modethe file permissions, almost always in octal. The first digit selects permissions for the user who owns the file: read (4), write (2), and execute (1); the second selects permissions for other users in the file's group, with the same values; and the third for other users not in the file's group, with the same values.
Use QTemporaryDir() or QTemporaryDir(directoryPrefix). If a specific mode was set, you'll need to use QFile::setPermissions on the temporary dir path.

Definition at line 81 of file ktempdir.cpp.

◆ ~KTempDir()

KTempDir::~KTempDir ( )

The destructor deletes the directory and its contents if autoRemove is set to true.

See also

Definition at line 128 of file ktempdir.cpp.

Member Function Documentation

◆ autoRemove()

bool KTempDir::autoRemove ( ) const
whether auto remove is active
See also

Definition at line 157 of file ktempdir.cpp.

◆ create()

bool KTempDir::create ( const QString directoryPrefix,
int  mode 

Creates a "random" directory with specified mode.

directoryPrefixto use when creating temp directory (the rest is generated randomly)
modedirectory permissions
true upon success

Definition at line 86 of file ktempdir.cpp.

◆ exists()

bool KTempDir::exists ( ) const

Returns true if a temporary directory has successfully been created and has not been unlinked yet.

use QTemporaryDir::isValid() + QDir::exists(path) if there's really a doubt that it might have been deleted meanwhile.

Definition at line 147 of file ktempdir.cpp.

◆ name()

QString KTempDir::name ( ) const

Returns the full path and name of the directory, including a trailing '/'.

The name of the directory, or QString() if creating the directory has failed or the directory has been unlinked
use QTemporaryDir::path()

Definition at line 142 of file ktempdir.cpp.

◆ removeDir()

bool KTempDir::removeDir ( const QString path)

Remove a directory and all its contents.

Remove recursively a directory, even if it is not empty or contains other directories.

However the function works too when the path given is a non-directory file. In that case it simply remove that file.

The function stops on the first error.

This function is more meant for removing a directory not created by the user. For user-created directories, using KIO::del() is recommended instead, especially as it has user feedback for long operations.
pathPath of the directory to delete
true if successful, otherwise false (Use errno for more details about the error.)
use QDir(path)::removeRecursively in Qt 5.

Definition at line 190 of file ktempdir.cpp.

◆ setAutoRemove()

void KTempDir::setAutoRemove ( bool  autoRemove)

Turn automatic deletion of the directory on or off.

Automatic deletion is on by default.

autoRemovetoggle automatic deletion on or off

Definition at line 152 of file ktempdir.cpp.

◆ status()

int KTempDir::status ( ) const

Returns the status of the directory creation based on errno.

(see errno.h)

You should check the status after object creation to check whether the directory could be created.
the errno status, 0 means ok
use QTemporaryDir::isValid()

Definition at line 137 of file ktempdir.cpp.

◆ unlink()

void KTempDir::unlink ( )

Deletes the directory recursively.

use QTemporaryDir::remove()

Definition at line 162 of file ktempdir.cpp.

The documentation for this class was generated from the following files:
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Wed Sep 27 2023 03:56:06 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.