CopperSpice API  1.9.1
QStandardPaths Class Reference

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

Public Typedefs

using LocateOptions = QFlags< LocateOption >
 

Public Types

enum  LocateOption
 
enum  StandardLocation
 

Static Public Methods

static QString displayName (StandardLocation type)
 
static QString findExecutable (const QString &executableName, const QStringList &paths=QStringList ())
 
static QString locate (StandardLocation type, const QString &fileName, LocateOptions options=LocateFile)
 
static QStringList locateAll (StandardLocation type, const QString &fileName, LocateOptions options=LocateFile)
 
static void setTestModeEnabled (bool testMode)
 
static QStringList standardLocations (StandardLocation type)
 
static QString writableLocation (StandardLocation type)
 

Detailed Description

The QStandardPaths class provides methods for accessing standard paths. This class contains functions to query standard locations on the local file system, for common tasks such as user-specific directories or system-wide configuration directories.

See also
writableLocation(), standardLocations(), displayName(), locate(), locateAll()

Member Typedef Documentation

Member Enumeration Documentation

This enum describes the different flags that can be used for controlling the behavior of QStandardPaths::locate and QStandardPaths::locateAll.

ConstantValueDescription
QStandardPaths::LocateFile 0x0 Return only files
QStandardPaths::LocateDirectory 0x1 Return only directories

This enum describes the different locations that can be queried using methods such as QStandardPaths::writableLocation, QStandardPaths::standardLocations, and QStandardPaths::displayName.

Some of the values in this enum represent a user configuration. Such enum values will return the same paths in different applications, so they could be used to share data with other applications. Other values are specific to this application. Each enum value in the table below describes whether it is application specific or generic.

Application specific directories should be assumed to be unreachable by other applications. Therefore, files placed there might not be readable by other applications, even if run by the same user. On the other hand, generic directories should be assumed to be accessible by all applications run by this user, but should still be assumed to be unreachable by applications by other users.

The only exception is QStandardPaths::TempLocation (which is the same as QDir::tempPath()): the path returned may be application-specific, but files stored there may be accessed by other applications run by the same user.

Data interchange with other users is out of the scope of QStandardPaths.

ConstantValueDescription
QStandardPaths::DesktopLocation 0 Returns the user's desktop directory. This is a generic value. On systems with no concept of a desktop, this is the same as QStandardPaths::HomeLocation.
QStandardPaths::DocumentsLocation 1 Returns the directory containing user document files. This is a generic value. The returned path is never empty.
QStandardPaths::FontsLocation 2 Returns the directory containing user's fonts. This is a generic value. Installing fonts may require additional, platform-specific operations.
QStandardPaths::ApplicationsLocation 3 Returns the directory containing the user applications (either executables, application bundles, or shortcuts to them). This is a generic value. Installing applications may require additional, platform-specific operations. Files, folders or shortcuts in this directory are platform-specific.
QStandardPaths::MusicLocation 4 Returns the directory containing the user's music or other audio files. This is a generic value. If no directory specific for music files exists, a sensible fallback for storing user documents is returned.
QStandardPaths::MoviesLocation 5 Returns the directory containing the user's movies and videos. This is a generic value. If no directory specific for movie files exists, a sensible fallback for storing user documents is returned.
QStandardPaths::PicturesLocation6Returns the directory containing the user's pictures or photos. This is a generic value. If no directory specific for picture files exists, a sensible fallback for storing user documents is returned.
QStandardPaths::TempLocation7Returns a directory where temporary files can be stored. The returned value might be application-specific, shared among other applications for this user, or even system-wide. The returned path is never empty.
QStandardPaths::HomeLocation8Returns the user's home directory (the same as QDir::homePath()). On Unix systems, this is equal to the HOME environment variable. This value might be generic or application-specific, but the returned path is never empty.
QStandardPaths::DataLocation9Returns a directory location where persistent application data can be stored. This is an application-specific directory. To obtain a path to store data to be shared with other applications, use QStandardPaths::GenericDataLocation. The returned path is never empty.
QStandardPaths::CacheLocation10Returns a directory location where user-specific non-essential (cached) data should be written. This is an application-specific directory. The returned path is never empty.
QStandardPaths::GenericDataLocation11Returns a directory location where persistent data shared across applications can be stored. This is a generic value. The returned path is never empty.
QStandardPaths::RuntimeLocation 12 Returns a directory location where runtime communication files should be written, like Unix local sockets. This is a generic value. The returned path may be empty on some systems.
QStandardPaths::ConfigLocation 13 Returns a directory location where user-specific configuration files should be written. This may be either a generic value or application-specific, and the returned path is never empty.
QStandardPaths::DownloadLocation 14 Returns a directory for user's downloaded files. This is a generic value. If no directory specific for downloads exists, a sensible fallback for storing user documents is returned.
QStandardPaths::GenericCacheLocation 15 Returns a directory location where user-specific non-essential (cached) data, shared across applications, should be written. This is a generic value. The returned path may be empty if the system has no concept of shared cache.
QStandardPaths::GenericConfigLocation 16 Returns a directory location where user-specific configuration files shared between multiple applications should be written. This is a generic value and the returned path is never empty.
QStandardPaths::AppDataLocation 17 Returns a directory location where persistent application data can be stored. This is an application-specific directory. To obtain a path to store data to be shared with other applications, use QStandardPaths::GenericDataLocation. The returned path is never empty. On the Windows operating system, this returns the roaming path.
QStandardPaths::AppConfigLocation 18 Returns a directory location where user-specific configuration files should be written. This is an application-specific directory, and the returned path is never empty.
QStandardPaths::AppLocalDataLocation DataLocation Returns the local settings path on the Windows operating system. On all other platforms, it returns the same value as AppDataLocation.

The following table shows examples of paths on different operating systems. These examples may not exactly conform to your particular operating system configuration or locale.

  • first path is the writable path unless noted
  • additional paths represent non-writable locations

The <APPNAME> is usually the organization name, application name, possibly both, or a unique name generated at packaging.

The <APPROOT> is the location where this application is installed, often a sandbox.

The <APPDIR> is the directory containing the application executable.

Path typeMac OS X
DesktopLocation"~/Desktop"
DocumentsLocation"~/Documents"
FontsLocation"/System/Library/Fonts" (not writable)
ApplicationsLocation"/Applications" (not writable)
MusicLocation"~/Music"
MoviesLocation"~/Movies"
PicturesLocation"~/Pictures"
TempLocationrandomly generated by the OS
HomeLocation"~"
DataLocation "~/Library/Application Support/<APPNAME>", "/Library/Application Support/<APPNAME>". "<APPDIR>/../Resources"
CacheLocation "~/Library/Caches/<APPNAME>", "/Library/Caches/<APPNAME>"
GenericDataLocation"~/Library/Application Support", "/Library/Application Support"
RuntimeLocation"~/Library/Application Support"
ConfigLocation"~/Library/Preferences"
GenericConfigLocation"~/Library/Preferences"
DownloadLocation"~/Documents"
GenericCacheLocation"~/Library/Caches", "/Library/Caches"
AppDataLocation"~/Library/Application Support/<APPNAME>", "/Library/Application Support/<APPNAME>". "<APPDIR>/../Resources"
AppConfigLocation"~/Library/Preferences/<APPNAME>"
AppLocalDataLocation"~/Library/Application Support/<APPNAME>", "/Library/Application Support/<APPNAME>". "<APPDIR>/../Resources"
Path typeWindows
DesktopLocation"C:/Users/<USER>/Desktop"
DocumentsLocation"C:/Users/<USER>/Documents"
FontsLocation"C:/Windows/Fonts" (not writable)
ApplicationsLocation"C:/Users/<USER>/AppData/Roaming/Microsoft/Windows/Start Menu/Programs"
MusicLocation"C:/Users/<USER>/Music"
MoviesLocation"C:/Users/<USER>/Videos"
PicturesLocation"C:/Users/<USER>/Pictures"
TempLocation"C:/Users/<USER>/AppData/Local/Temp"
HomeLocation"C:/Users/<USER>"
DataLocation "C:/Users/<USER>/AppData/Local/<APPNAME>", "C:/ProgramData/<APPNAME>", "<APPDIR>", "<APPDIR>/data"
CacheLocation "C:/Users/<USER>/AppData/Local/<APPNAME>/cache"
GenericDataLocation"C:/Users/<USER>/AppData/Local", "C:/ProgramData"
RuntimeLocation"C:/Users/<USER>"
ConfigLocation"C:/Users/<USER>/AppData/Local/<APPNAME>", "C:/ProgramData/<APPNAME>"
GenericConfigLocation"C:/Users/<USER>/AppData/Local", "C:/ProgramData"
DownloadLocation"C:/Users/<USER>/Documents"
GenericCacheLocation"C:/Users/<USER>/AppData/Local/cache"
AppDataLocation"C:/Users/<USER>/AppData/Roaming/<APPNAME>", "C:/ProgramData/<APPNAME>", "<APPDIR>", "<APPDIR>/data"
AppConfigLocation"C:/Users/<USER>/AppData/Local/<APPNAME>", "C:/ProgramData/<APPNAME>"
AppLocalDataLocation"C:/Users/<USER>/AppData/Local/<APPNAME>", "C:/ProgramData/<APPNAME>", "<APPDIR>", "<APPDIR>/data"
Path typeLinux
DesktopLocation"~/Desktop"
DocumentsLocation"~/Documents"
FontsLocation"~/.fonts"
ApplicationsLocation"~/.local/share/applications", "/usr/local/share/applications", "/usr/share/applications"
MusicLocation"~/Music"
MoviesLocation"~/Videos"
PicturesLocation"~/Pictures"
TempLocation"/tmp"
HomeLocation"~"
DataLocation"~/.local/share/<APPNAME>", "/usr/local/share/<APPNAME>", "/usr/share/<APPNAME>"
CacheLocation"~/.cache/<APPNAME>"
GenericDataLocation"~/.local/share", "/usr/local/share", "/usr/share"
RuntimeLocation"/run/user/<USER>"
ConfigLocation"~/.config", "/etc/xdg"
GenericConfigLocation"~/.config", "/etc/xdg"
DownloadLocation"~/Downloads"
GenericCacheLocation"~/.cache"
AppDataLocation"~/.local/share/<APPNAME>", "/usr/local/share/<APPNAME>", "/usr/share/<APPNAME>"
AppConfigLocation"~/.config/<APPNAME>", "/etc/xdg/<APPNAME>"
AppLocalDataLocation"~/.local/share/<APPNAME>", "/usr/local/share/<APPNAME>", "/usr/share/<APPNAME>"
See also
writableLocation(), standardLocations(), displayName(), locate(), locateAll()

Method Documentation

QString QStandardPaths::displayName ( StandardLocation  type)
static

Returns a localized display name for the given location type or an empty QString if no relevant location can be found.

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

Finds the executable named executableName in the paths specified by paths, or the system paths if paths is empty. On most operating systems the system path is determined by the PATH environment variable. The directories where to search for the executable can be set in the paths argument. To search in both your own paths and the system paths, call findExecutable twice, once with paths set and once with paths empty.

Symlinks are not resolved, in order to preserve behavior for the case of executables whose behavior depends on the name they are invoked with.

Note
On Windows, the usual executable extensions (from the PATHEXT environment variable) are automatically appended, so that for instance findExecutable("foo") will find foo.exe or foo.bat if present. Returns the absolute file path to the executable, or an empty string if not found.
QString QStandardPaths::locate ( StandardLocation  type,
const QString fileName,
LocateOptions  options = LocateFile 
)
static

Tries to find a file or directory called fileName in the standard locations for type. The full path to the first file or directory (depending on options) found is returned. If no such file or directory can be found, an empty string is returned.

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

Tries to find all files or directories called fileName in the standard locations for type. The options flag allows to specify whether to look for files or directories. Returns the list of all the files that were found.

void QStandardPaths::setTestModeEnabled ( bool  testMode)
static

If testMode is true, this enables a special "test mode" in QStandardPaths, which changes writable locations to point to test directories, in order to prevent auto tests from reading from or writing to the current user's configuration.

This affects the locations into which test programs might write files: GenericDataLocation, DataLocation, ConfigLocation, GenericConfigLocation, GenericCacheLocation, CacheLocation. Other locations are not affected.

On Unix, XDG_DATA_HOME is set to ~/.qttest/share, XDG_CONFIG_HOME is set to ~/.qttest/config, and XDG_CACHE_HOME is set to ~/.qttest/cache.

On Mac OS X, data goes to "~/.qttest/Application Support", cache goes to ~/.qttest/Cache, and config goes to ~/.qttest/Preferences.

On Windows, everything goes to a "qttest" directory under Application Data.

QStringList QStandardPaths::standardLocations ( StandardLocation  type)
static

Returns all the directories where files of type belong. The list of directories is sorted from high to low priority, starting with writableLocation() if it can be determined. This list is empty if no locations for type are defined.

See also
writableLocation()
QString QStandardPaths::writableLocation ( StandardLocation  type)
static

Returns the directory where files of type should be written to, or an empty string if the location can not be determined. The storage location returned can be a directory that does not exist.