QStandardPaths Class
The QStandardPaths class provides methods for accessing standard paths. More…
| Header | #include <QStandardPaths> |
|---|---|
| CMake | target_link_libraries(app PRIVATE Nt::Core) |
| Module | Nt Core C++ Classes |
List of all members, including inherited members
Public Types
| enum | StandardLocation |
| enum | LocateOption |
| typedef | LocateOptions |
Static Public Members
| QString | writableLocation(StandardLocation type) |
| QStringList | standardLocations(StandardLocation type) |
| QString | locate(StandardLocation type, const QString &fileName, LocateOptions options = LocateFile) |
| QStringList | locateAll(StandardLocation type, const QString &fileName, LocateOptions options = LocateFile) |
| QString | displayName(StandardLocation type) |
| QString | findExecutable(const QString &executableName, const QStringList &paths = QStringList()) |
| void | setTestModeEnabled(bool testMode) |
| bool | isTestModeEnabled() |
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.
| Constant | Description |
|---|---|
QStandardPaths::LocateFile | Return only regular files. |
QStandardPaths::LocateDirectory | Return only directories. |
typedef QStandardPaths::LocateOptions
A QFlags of LocateOption values.
enum QStandardPaths::StandardLocation
Identifies a kind of standard location.
| Constant | Description |
|---|---|
QStandardPaths::DesktopLocation | The user's desktop directory. |
QStandardPaths::DocumentsLocation | The user's documents directory. |
QStandardPaths::FontsLocation | The directory for fonts, below the XDG data home. |
QStandardPaths::ApplicationsLocation | The directory for desktop entries, below the XDG data home. |
QStandardPaths::MusicLocation | The user's music directory. |
QStandardPaths::MoviesLocation | The user's videos directory. |
QStandardPaths::PicturesLocation | The user's pictures directory. |
QStandardPaths::TempLocation | The directory for temporary files, as returned by QDir::tempPath(). |
QStandardPaths::HomeLocation | The user's home directory. |
QStandardPaths::AppLocalDataLocation | The application's data directory below the XDG data home. Same as AppDataLocation. |
QStandardPaths::CacheLocation | The application's cache directory below the XDG cache home. |
QStandardPaths::GenericDataLocation | The XDG data home, shared by all applications. |
QStandardPaths::RuntimeLocation | The directory for runtime files such as sockets (XDG_RUNTIME_DIR). |
QStandardPaths::ConfigLocation | The XDG configuration home. Same as GenericConfigLocation. |
QStandardPaths::DownloadLocation | The user's download directory. |
QStandardPaths::GenericCacheLocation | The XDG cache home, shared by all applications. |
QStandardPaths::GenericConfigLocation | The XDG configuration home, shared by all applications. |
QStandardPaths::AppDataLocation | The application's data directory below the XDG data home. |
QStandardPaths::AppConfigLocation | The application's configuration directory below the XDG configuration home. |
QStandardPaths::PublicShareLocation | The user's public share directory. |
QStandardPaths::TemplatesLocation | The user's templates directory. |
QStandardPaths::StateLocation | The application's state directory below the XDG state home. |
QStandardPaths::GenericStateLocation | The XDG state home, shared by all applications. |
Member Function Documentation
QString QStandardPaths::displayName(StandardLocation type)
Returns a human-readable, untranslated English name for the location type.
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.
bool QStandardPaths::isTestModeEnabled()
Returns true if test mode is enabled.
This function was introduced in 5.2.
See also setTestModeEnabled().
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().
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().
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().
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().
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().