Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
QStandardPaths Class Reference

\inmodule QtCore More...

#include <qstandardpaths.h>

+ Collaboration diagram for QStandardPaths:

Public Types

enum  StandardLocation {
  DesktopLocation , DocumentsLocation , FontsLocation , ApplicationsLocation ,
  MusicLocation , MoviesLocation , PicturesLocation , TempLocation ,
  HomeLocation , AppLocalDataLocation , CacheLocation , GenericDataLocation ,
  RuntimeLocation , ConfigLocation , DownloadLocation , GenericCacheLocation ,
  GenericConfigLocation , AppDataLocation , AppConfigLocation , PublicShareLocation ,
  TemplatesLocation , StateLocation , GenericStateLocation
}
 This enum describes the different locations that can be queried using methods such as QStandardPaths::writableLocation, QStandardPaths::standardLocations, and QStandardPaths::displayName. More...
 
enum  LocateOption { LocateFile = 0x0 , LocateDirectory = 0x1 }
 This enum describes the different flags that can be used for controlling the behavior of QStandardPaths::locate and QStandardPaths::locateAll. More...
 

Static Public Member Functions

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

Detailed Description

\inmodule QtCore

The QStandardPaths class provides methods for accessing standard paths.

Since
5.0

This class contains functions to query standard locations on the local filesystem, for common tasks such as user-specific directories or system-wide configuration directories.

Definition at line 15 of file qstandardpaths.h.

Member Enumeration Documentation

◆ LocateOption

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

\value LocateFile return only files \value LocateDirectory return only directories

Enumerator
LocateFile 
LocateDirectory 

Definition at line 50 of file qstandardpaths.h.

◆ StandardLocation

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's 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.

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

\value DesktopLocation 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. \value DocumentsLocation Returns the directory containing user document files. This is a generic value. The returned path is never empty. \value FontsLocation Returns the directory containing user's fonts. This is a generic value. Note that installing fonts may require additional, platform-specific operations. \value ApplicationsLocation Returns the directory containing the user applications (either executables, application bundles, or shortcuts to them). This is a generic value. Note that installing applications may require additional, platform-specific operations. Files, folders or shortcuts in this directory are platform-specific. \value MusicLocation 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. \value MoviesLocation 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. \value PicturesLocation Returns 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. \value TempLocation Returns 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. \value HomeLocation Returns 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. \value AppLocalDataLocation Returns the local settings path on the Windows operating system. On all other platforms, it returns the same value as AppDataLocation. This enum value was added in Qt 5.4. \value CacheLocation Returns 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. \value GenericCacheLocation Returns a directory location where user-specific non-essential (cached) data, shared across applications, should be written. This is a generic value. Note that the returned path may be empty if the system has no concept of shared cache. \value GenericDataLocation Returns a directory location where persistent data shared across applications can be stored. This is a generic value. The returned path is never empty. \value RuntimeLocation 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. \value ConfigLocation 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. \value DownloadLocation 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. \value GenericConfigLocation 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. \value AppDataLocation 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. This enum value was added in Qt 5.4. \value AppConfigLocation 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. This enum value was added in Qt 5.5. \value PublicShareLocation Returns a directory location where user-specific publicly shared files and directories can be stored. This is a generic value. Note that the returned path may be empty if the system has no concept of a publicly shared location. This enum value was added in Qt 6.4. \value TemplatesLocation Returns a directory location where user-specific template files can be stored. This is a generic value. Note that the returned path may be empty if the system has no concept of a templates location. This enum value was added in Qt 6.4. \value [since 6.7] StateLocation Returns a directory location where user-specific application state data files should be written. This is an application-specific directory, and the returned path is never empty. \value [since 6.7] GenericStateLocation Returns a directory location where shared state data files across applications should be written. This value might be generic or application-specific, but the returned path is never empty.

The following table gives examples of paths on different operating systems. The first path is the writable path (unless noted). Other, additional paths, if any, represent non-writable locations.

\table \header

  • Path type
  • \macos
  • Windows \row
  • DesktopLocation
  • "~/Desktop"
  • "C:/Users/<USER>/Desktop" \row
  • DocumentsLocation
  • "~/Documents"
  • "C:/Users/<USER>/Documents" \row
  • FontsLocation
  • "/System/Library/Fonts" (not writable)
  • "C:/Windows/Fonts" (not writable) \row
  • ApplicationsLocation
  • "/Applications" (not writable)
  • "C:/Users/<USER>/AppData/Roaming/Microsoft/Windows/Start Menu/Programs" \row
  • MusicLocation
  • "~/Music"
  • "C:/Users/<USER>/Music" \row
  • MoviesLocation
  • "~/Movies"
  • "C:/Users/<USER>/Videos" \row
  • PicturesLocation
  • "~/Pictures"
  • "C:/Users/<USER>/Pictures" \row
  • TempLocation
  • randomly generated by the OS
  • "C:/Users/<USER>/AppData/Local/Temp" \row
  • HomeLocation
  • "~"
  • "C:/Users/<USER>" \row
  • AppLocalDataLocation
  • "~/Library/Application Support/<APPNAME>", "/Library/Application Support/<APPNAME>". "<APPDIR>/../Resources"
  • "C:/Users/<USER>/AppData/Local/<APPNAME>", "C:/ProgramData/<APPNAME>", "<APPDIR>", "<APPDIR>/data", "<APPDIR>/data/<APPNAME>" \row
  • CacheLocation
  • "~/Library/Caches/<APPNAME>", "/Library/Caches/<APPNAME>"
  • "C:/Users/<USER>/AppData/Local/<APPNAME>/cache" \row
  • StateLocation
  • "~/Library/Preferences/<APPNAME>/State"
  • "C:/Users/<USER>/AppData/Local/<APPNAME>/State", "C:/ProgramData/<APPNAME>/State" \row
  • GenericDataLocation
  • "~/Library/Application Support", "/Library/Application Support"
  • "C:/Users/<USER>/AppData/Local", "C:/ProgramData", "<APPDIR>", "<APPDIR>/data" \row
  • RuntimeLocation
  • "~/Library/Application Support"
  • "C:/Users/<USER>" \row
  • ConfigLocation
  • "~/Library/Preferences"
  • "C:/Users/<USER>/AppData/Local/<APPNAME>", "C:/ProgramData/<APPNAME>" \row
  • GenericConfigLocation
  • "~/Library/Preferences"
  • "C:/Users/<USER>/AppData/Local", "C:/ProgramData" \row
  • DownloadLocation
  • "~/Downloads"
  • "C:/Users/<USER>/Downloads" \row
  • GenericCacheLocation
  • "~/Library/Caches", "/Library/Caches"
  • "C:/Users/<USER>/AppData/Local/cache" \row
  • GenericStateLocation
  • "~/Library/Preferences/State"
  • "C:/Users/<USER>/AppData/Local/State", "C:/ProgramData/State" \row
  • AppDataLocation
  • "~/Library/Application Support/<APPNAME>", "/Library/Application Support/<APPNAME>". "<APPDIR>/../Resources"
  • "C:/Users/<USER>/AppData/Roaming/<APPNAME>", "C:/ProgramData/<APPNAME>", "<APPDIR>", "<APPDIR>/data", "<APPDIR>/data/<APPNAME>" \row
  • AppConfigLocation
  • "~/Library/Preferences/<APPNAME>"
  • "C:/Users/<USER>/AppData/Local/<APPNAME>", "C:/ProgramData/<APPNAME>" \row
  • PublicShareLocation
  • "~/Public"
  • "C:/Users/Public" \row
  • TemplatesLocation
  • "~/Templates"
  • "C:/Users/<USER>/AppData/Roaming/Microsoft/Windows/Templates" \endtable

\table \header

  • Path type
  • Linux and other UNIX operating systems \row
  • DesktopLocation
  • "~/Desktop" \row
  • DocumentsLocation
  • "~/Documents" \row
  • FontsLocation
  • "~/.fonts", "~/.local/share/fonts", "/usr/local/share/fonts", "/usr/share/fonts" \row
  • ApplicationsLocation
  • "~/.local/share/applications", "/usr/local/share/applications", "/usr/share/applications" \row
  • MusicLocation
  • "~/Music" \row
  • MoviesLocation
  • "~/Videos" \row
  • PicturesLocation
  • "~/Pictures" \row
  • TempLocation
  • "/tmp" \row
  • HomeLocation
  • "~" \row
  • AppLocalDataLocation
  • "~/.local/share/<APPNAME>", "/usr/local/share/<APPNAME>", "/usr/share/<APPNAME>" \row
  • CacheLocation
  • "~/.cache/<APPNAME>" \row
  • StateLocation
  • "~/.local/state/<APPNAME>" \row
  • GenericDataLocation
  • "~/.local/share", "/usr/local/share", "/usr/share" \row
  • RuntimeLocation
  • "/run/user/<USER>" \row
  • ConfigLocation
  • "~/.config", "/etc/xdg" \row
  • GenericConfigLocation
  • "~/.config", "/etc/xdg" \row
  • DownloadLocation
  • "~/Downloads" \row
  • GenericCacheLocation
  • "~/.cache" \row
  • GenericStateLocation
  • "~/.local/state" \row
  • AppDataLocation
  • "~/.local/share/<APPNAME>", "/usr/local/share/<APPNAME>", "/usr/share/<APPNAME>" \row
  • AppConfigLocation
  • "~/.config/<APPNAME>", "/etc/xdg/<APPNAME>" \row
  • PublicShareLocation
  • "~/Public" \row
  • TemplatesLocation
  • "~/Templates" \endtable

\table \header

  • Path type
  • Android
  • iOS \row
  • DesktopLocation
  • "<APPROOT>/files"
  • "<APPROOT>/Documents/Desktop" \row
  • DocumentsLocation
  • "<USER>/Documents" [*], "<USER>/<APPNAME>/Documents"
  • "<APPROOT>/Documents" \row
  • FontsLocation
  • "/system/fonts" (not writable)
  • "<APPROOT>/Library/Fonts" \row
  • ApplicationsLocation
  • not supported (directory not readable)
  • not supported \row
  • MusicLocation
  • "<USER>/Music" [*], "<USER>/<APPNAME>/Music"
  • "<APPROOT>/Documents/Music" \row
  • MoviesLocation
  • "<USER>/Movies" [*], "<USER>/<APPNAME>/Movies"
  • "<APPROOT>/Documents/Movies" \row
  • PicturesLocation
  • "<USER>/Pictures" [*], "<USER>/<APPNAME>/Pictures"
  • "<APPROOT>/Documents/Pictures", "assets-library://" \row
  • TempLocation
  • "<APPROOT>/cache"
  • "<APPROOT>/tmp" \row
  • HomeLocation
  • "<APPROOT>/files"
  • system defined \row
  • AppLocalDataLocation
  • "<APPROOT>/files", "<USER>/<APPNAME>/files"
  • "<APPROOT>/Library/Application Support" \row
  • CacheLocation
  • "<APPROOT>/cache", "<USER>/<APPNAME>/cache"
  • "<APPROOT>/Library/Caches" \row
  • StateLocation
  • "<APPROOT>/files/state" \row
  • GenericStateLocation (there is shared state)
  • "<APPROOT>/files/state" \row
  • GenericDataLocation
  • "<USER>" [*] or "<USER>/<APPNAME>/files"
  • "<APPROOT>/Library/Application Support" \row
  • RuntimeLocation
  • "<APPROOT>/cache"
  • not supported \row
  • ConfigLocation
  • "<APPROOT>/files/settings"
  • "<APPROOT>/Library/Preferences" \row
  • GenericConfigLocation
  • "<APPROOT>/files/settings" (there is no shared settings)
  • "<APPROOT>/Library/Preferences" \row
  • DownloadLocation
  • "<USER>/Downloads" [*], "<USER>/<APPNAME>/Downloads"
  • "<APPROOT>/Documents/Downloads" \row
  • GenericCacheLocation
  • "<APPROOT>/cache" (there is no shared cache)
  • "<APPROOT>/Library/Caches" \row
  • AppDataLocation
  • "<APPROOT>/files", "<USER>/<APPNAME>/files"
  • "<APPROOT>/Library/Application Support" \row
  • AppConfigLocation
  • "<APPROOT>/files/settings"
  • "<APPROOT>/Library/Preferences/<APPNAME>" \row
  • PublicShareLocation
  • not supported
  • not supported \row
  • TemplatesLocation
  • not supported
  • not supported \endtable

In the table above, <APPNAME> is usually the organization name, the application name, or both, or a unique name generated at packaging. Similarly, <APPROOT> is the location where this application is installed (often a sandbox). <APPDIR> is the directory containing the application executable.

The paths above should not be relied upon, as they may change according to OS configuration, locale, or they may change in future Qt versions.

Note
On Android, applications with open files on the external storage (<USER> locations), will be killed if the external storage is unmounted.
On Android 6.0 (API 23) or higher, the "WRITE_EXTERNAL_STORAGE" permission must be requested at runtime when using QStandardPaths::writableLocation or QStandardPaths::standardLocations.
On Android, reading/writing to GenericDataLocation needs the READ_EXTERNAL_STORAGE/WRITE_EXTERNAL_STORAGE permission granted.
[*] On Android 11 and above, public directories are no longer directly accessible in scoped storage mode. Thus, paths of the form "<USER>/DirName" are not returned. Instead, you can use \l QFileDialog which uses the Storage Access Framework (SAF) to access such directories.
On iOS, if you do pass {QStandardPaths::standardLocations(QStandardPaths::PicturesLocation).last()} as argument to \l{QFileDialog::setDirectory()}, a native image picker dialog will be used for accessing the user's photo album. The filename returned can be loaded using QFile and related APIs. This feature was added in Qt 5.5.
See also
writableLocation(), standardLocations(), displayName(), locate(), locateAll()
Enumerator
DesktopLocation 
DocumentsLocation 
FontsLocation 
ApplicationsLocation 
MusicLocation 
MoviesLocation 
PicturesLocation 
TempLocation 
HomeLocation 
AppLocalDataLocation 
CacheLocation 
GenericDataLocation 
RuntimeLocation 
ConfigLocation 
DownloadLocation 
GenericCacheLocation 
GenericConfigLocation 
AppDataLocation 
AppConfigLocation 
PublicShareLocation 
TemplatesLocation 
StateLocation 
GenericStateLocation 

Definition at line 20 of file qstandardpaths.h.

Member Function Documentation

◆ displayName()

QString QStandardPaths::displayName ( StandardLocation type)
static

displayName

Definition at line 549 of file qstandardpaths.cpp.

References AppConfigLocation, AppDataLocation, ApplicationsLocation, AppLocalDataLocation, CacheLocation, ConfigLocation, DesktopLocation, DocumentsLocation, DownloadLocation, FontsLocation, GenericCacheLocation, GenericConfigLocation, GenericDataLocation, GenericStateLocation, HomeLocation, MoviesLocation, MusicLocation, PicturesLocation, PublicShareLocation, RuntimeLocation, StateLocation, TemplatesLocation, TempLocation, and QCoreApplication::translate().

Referenced by QQmlStandardPaths::displayName(), and main().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ findExecutable()

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

findExecutable

Definition at line 486 of file qstandardpaths.cpp.

References Qt::CaseInsensitive, checkExecutable(), QDir::cleanPath(), QString::endsWith(), QString::fromLocal8Bit(), QString::isEmpty(), QDir::listSeparator(), Q_UNLIKELY, qgetenv(), searchExecutable(), QString::size(), Qt::SkipEmptyParts, QFileInfo::suffix(), and QString::truncate().

Referenced by QIBusPlatformInputContextPrivate::QIBusPlatformInputContextPrivate(), QCoreApplication::applicationFilePath(), QQmlStandardPaths::findExecutable(), findInPath(), and main().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isTestModeEnabled()

bool QStandardPaths::isTestModeEnabled ( )
static

Returns true if test mode is enabled in QStandardPaths; otherwise returns false.

Definition at line 624 of file qstandardpaths.cpp.

References qsp_testMode.

Referenced by appendTestMode(), and testDir().

+ Here is the caller graph for this function:

◆ locate()

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

locate

Definition at line 401 of file qstandardpaths.cpp.

References QString::constBegin(), QString::constEnd(), dir, existsAsSpecified(), fileName, and standardLocations().

Referenced by QLoggingRegistry::initializeRules(), QQmlStandardPaths::locate(), main(), resolveBugListFile(), QQmlToolingSettings::search(), and QGuiApplication::setDesktopFileName().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ locateAll()

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

[0]

[1]

locateAll

Definition at line 415 of file qstandardpaths.cpp.

References QString::append(), QString::constBegin(), QString::constEnd(), dir, existsAsSpecified(), fileName, and standardLocations().

Referenced by QQmlStandardPaths::locateAll(), locateMimeDirectories(), main(), and QGenericUnixTheme::xdgIconThemePaths().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setTestModeEnabled()

void QStandardPaths::setTestModeEnabled ( bool testMode)
static

setTestModeEnabled

Definition at line 611 of file qstandardpaths.cpp.

References qsp_testMode.

Referenced by main().

+ Here is the caller graph for this function:

◆ standardLocations()

QStringList QStandardPaths::standardLocations ( StandardLocation type)
static

standardLocations

See also
writableLocation()

Definition at line 228 of file qstandardpaths_android.cpp.

References AppDataLocation, AppLocalDataLocation, ba, CacheLocation, QDir::cleanPath(), DocumentsLocation, DownloadLocation, FontsLocation, QString::fromLocal8Bit(), getExternalCacheDir(), getExternalFilesDir(), getExternalStoragePublicDirectory(), QByteArray::isEmpty(), QString::isEmpty(), MoviesLocation, MusicLocation, PicturesLocation, qgetenv(), QStringLiteral, and writableLocation().

Referenced by QConfFileSettingsPrivate::QConfFileSettingsPrivate(), QPlaceManagerEngineNokiaV2::QPlaceManagerEngineNokiaV2(), QQmlPreviewFileLoader::QQmlPreviewFileLoader(), loadFileDialog(), locate(), locateAll(), main(), and QQmlStandardPaths::standardLocations().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ writableLocation()

QString QStandardPaths::writableLocation ( StandardLocation type)
static

writableLocation

Definition at line 181 of file qstandardpaths_android.cpp.

References AppConfigLocation, AppDataLocation, ApplicationsLocation, AppLocalDataLocation, CacheLocation, ConfigLocation, DesktopLocation, DocumentsLocation, DownloadLocation, FontsLocation, GenericCacheLocation, GenericConfigLocation, GenericDataLocation, GenericStateLocation, getCacheDir(), getExternalFilesDir(), getExternalStorageDirectory(), getFilesDir(), getSdkBasedExternalDir(), HomeLocation, MoviesLocation, MusicLocation, PicturesLocation, PublicShareLocation, RuntimeLocation, StateLocation, TemplatesLocation, TempLocation, and testDir().

Referenced by QOpenGLProgramBinaryCache::QOpenGLProgramBinaryCache(), QWaylandCompositorPrivate::QWaylandCompositorPrivate(), QtWaylandClient::QWaylandShmBuffer::QWaylandShmBuffer(), QHstsStore::absoluteFilePath(), automaticPipelineCacheDir(), QAbstractGeoTileCache::baseCacheDirectory(), QMediaStorageLocation::defaultDirectory(), QIBusPlatformInputContextPrivate::getSocketPath(), iconTempPath(), QT_BEGIN_NAMESPACE::lastPositionFilePath(), QV4::CompiledData::CompilationUnit::localCacheFilePath(), main(), make_user_path(), QQmlEngine::offlineStoragePath(), persistentQsbcDir(), standardLocations(), and QQmlStandardPaths::writableLocation().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

The documentation for this class was generated from the following files: