6.0.0-rc4Source

QStandardPaths Class

The QStandardPaths class provides methods for accessing standard paths. More…

Header#include <QStandardPaths>
CMaketarget_link_libraries(app PRIVATE Nt::Core)
ModuleNt Core C++ Classes

List of all members, including inherited members

Public Types

Static Public Members

QStringwritableLocation(StandardLocation type)
QStringListstandardLocations(StandardLocation type)
QStringlocate(StandardLocation type, const QString &fileName, LocateOptions options = LocateFile)
QStringListlocateAll(StandardLocation type, const QString &fileName, LocateOptions options = LocateFile)
QStringdisplayName(StandardLocation type)
QStringfindExecutable(const QString &executableName, const QStringList &paths = QStringList())
voidsetTestModeEnabled(bool testMode)
boolisTestModeEnabled()

Detailed Description

The class locates the directories where a program should keep documents, configuration, cache and other data, following the XDG base directory specification. All functions are static.

const QString dir = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
const QString exe = QStandardPaths::findExecutable("git");

Differences from Qt

Only the XDG layout of Linux and other POSIX systems is supported. The application sub-directory is the executable's file name, not the organization and application names. displayName() returns untranslated English names.

On Zephyr the locations are still those of a Linux desktop and do not exist; choose paths on a mounted file system yourself. See Nt on Zephyr.

Member Type Documentation

enum QStandardPaths::LocateOption

Controls what locate() and locateAll() search for.

ConstantDescription
QStandardPaths::LocateFileReturn only regular files.
QStandardPaths::LocateDirectoryReturn only directories.

typedef QStandardPaths::LocateOptions

A QFlags of LocateOption values.

enum QStandardPaths::StandardLocation

Identifies a kind of standard location.

ConstantDescription
QStandardPaths::DesktopLocationThe user's desktop directory.
QStandardPaths::DocumentsLocationThe user's documents directory.
QStandardPaths::FontsLocationThe directory for fonts, below the XDG data home.
QStandardPaths::ApplicationsLocationThe directory for desktop entries, below the XDG data home.
QStandardPaths::MusicLocationThe user's music directory.
QStandardPaths::MoviesLocationThe user's videos directory.
QStandardPaths::PicturesLocationThe user's pictures directory.
QStandardPaths::TempLocationThe directory for temporary files, as returned by QDir::tempPath().
QStandardPaths::HomeLocationThe user's home directory.
QStandardPaths::AppLocalDataLocationThe application's data directory below the XDG data home. Same as AppDataLocation.
QStandardPaths::CacheLocationThe application's cache directory below the XDG cache home.
QStandardPaths::GenericDataLocationThe XDG data home, shared by all applications.
QStandardPaths::RuntimeLocationThe directory for runtime files such as sockets (XDG_RUNTIME_DIR).
QStandardPaths::ConfigLocationThe XDG configuration home. Same as GenericConfigLocation.
QStandardPaths::DownloadLocationThe user's download directory.
QStandardPaths::GenericCacheLocationThe XDG cache home, shared by all applications.
QStandardPaths::GenericConfigLocationThe XDG configuration home, shared by all applications.
QStandardPaths::AppDataLocationThe application's data directory below the XDG data home.
QStandardPaths::AppConfigLocationThe application's configuration directory below the XDG configuration home.
QStandardPaths::PublicShareLocationThe user's public share directory.
QStandardPaths::TemplatesLocationThe user's templates directory.
QStandardPaths::StateLocationThe application's state directory below the XDG state home.
QStandardPaths::GenericStateLocationThe XDG state home, shared by all applications.

Member Function Documentation

[static] QString QStandardPaths::displayName(StandardLocation type)

Returns a human-readable, untranslated English name for the location type.

[static] QString QStandardPaths::findExecutable(const QString &executableName, const QStringList &paths = QStringList())

Finds an executable file named executableName and returns its absolute path, or an empty string if none is found. If executableName contains a slash it is tested directly. Otherwise each directory in paths is searched, or in the PATH environment variable if paths is empty.

[static] bool QStandardPaths::isTestModeEnabled()

Returns true if test mode is enabled.

This function was introduced in 5.2.

See also setTestModeEnabled().

[static] QString QStandardPaths::locate(StandardLocation type, const QString &fileName, LocateOptions options = LocateFile)

Finds the first entry named fileName in the standard locations of the given type that matches options. Returns its full path, or an empty string if there is none. If fileName is empty, the location directory itself is tested.

See also locateAll() and standardLocations().

[static] QStringList QStandardPaths::locateAll(StandardLocation type, const QString &fileName, LocateOptions options = LocateFile)

Finds every entry named fileName in the standard locations of the given type that matches options. Returns their full paths in search order.

See also locate() and standardLocations().

[static] void QStandardPaths::setTestModeEnabled(bool testMode)

Enables test mode if testMode is true, or disables it. In test mode the data, configuration, cache and state locations are sub-directories of ~/.qttest (share, config, cache and state), and standardLocations() returns only the writable location, so that tests do not read or change the user's real files.

This function was introduced in 5.2.

See also isTestModeEnabled().

[static] QStringList QStandardPaths::standardLocations(StandardLocation type)

Returns all directories of the given type, with the writable location first. The result does not contain empty or duplicate entries, and the directories are not checked for existence.

See also writableLocation() and locateAll().

[static] QString QStandardPaths::writableLocation(StandardLocation type)

Returns the directory where files of the given type should be written, or an empty string if the location cannot be determined. The directory is not created.

See also standardLocations() and locate().