QStandardPaths Class

  • Header: QStandardPaths

  • Since: Qt 5.0

  • CMake:

    find_package(Qt6 REQUIRED COMPONENTS Core)

    target_link_libraries(mytarget PRIVATE Qt6::Core)

  • qmake: QT += core

Detailed Description

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.

Member Type Documentation

 

enum QStandardPaths::LocateOption

flags QStandardPaths::LocateOptions

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

Constant

Value

Description

QStandardPaths::LocateFile

0x0

return only files

QStandardPaths::LocateDirectory

0x1

return only directories

The LocateOptions type is a typedef for QFlags<LocateOption>. It stores an OR combination of LocateOption values.

enum QStandardPaths::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.

Constant

Value

Description

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. Note that 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. Note that 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::PicturesLocation

6

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.

QStandardPaths::TempLocation

7

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.

QStandardPaths::HomeLocation

8

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.

QStandardPaths::AppLocalDataLocation

9

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.

QStandardPaths::CacheLocation

10

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.

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. Note that the returned path may be empty if the system has no concept of shared cache.

QStandardPaths::GenericDataLocation

11

Returns 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::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. This enum value was added in Qt 5.4.

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. This enum value was added in Qt 5.5.

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.

Path type

macOS

Windows

DesktopLocation

"~/Desktop"

"C:/Users/<USER>/Desktop"

DocumentsLocation

"~/Documents"

"C:/Users/<USER>/Documents"

FontsLocation

"/System/Library/Fonts" (not writable)

"C:/Windows/Fonts" (not writable)

ApplicationsLocation

"/Applications" (not writable)

"C:/Users/<USER>/AppData/Roaming/Microsoft/Windows/Start Menu/Programs"

MusicLocation

"~/Music"

"C:/Users/<USER>/Music"

MoviesLocation

"~/Movies"

"C:/Users/<USER>/Videos"

PicturesLocation

"~/Pictures"

"C:/Users/<USER>/Pictures"

TempLocation

randomly generated by the OS

"C:/Users/<USER>/AppData/Local/Temp"

HomeLocation

"~"

"C:/Users/<USER>"

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>"

CacheLocation

"~/Library/Caches/<APPNAME>", "/Library/Caches/<APPNAME>"

"C:/Users/<USER>/AppData/Local/<APPNAME>/cache"

GenericDataLocation

"~/Library/Application Support", "/Library/Application Support"

"C:/Users/<USER>/AppData/Local", "C:/ProgramData", "<APPDIR>", "<APPDIR>/data"

RuntimeLocation

"~/Library/Application Support"

"C:/Users/<USER>"

ConfigLocation

"~/Library/Preferences"

"C:/Users/<USER>/AppData/Local/<APPNAME>", "C:/ProgramData/<APPNAME>"

GenericConfigLocation

"~/Library/Preferences"

"C:/Users/<USER>/AppData/Local", "C:/ProgramData"

DownloadLocation

"~/Downloads"

"C:/Users/<USER>/Downloads"

GenericCacheLocation

"~/Library/Caches", "/Library/Caches"

"C:/Users/<USER>/AppData/Local/cache"

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>"

AppConfigLocation

"~/Library/Preferences/<APPNAME>"

"C:/Users/<USER>/AppData/Local/<APPNAME>", "C:/ProgramData/<APPNAME>"

Path type

Linux and other UNIX operating systems

DesktopLocation

"~/Desktop"

DocumentsLocation

"~/Documents"

FontsLocation

"~/.fonts", "~/.local/share/fonts", "/usr/local/share/fonts", "/usr/share/fonts"

ApplicationsLocation

"~/.local/share/applications", "/usr/local/share/applications", "/usr/share/applications"

MusicLocation

"~/Music"

MoviesLocation

"~/Videos"

PicturesLocation

"~/Pictures"

TempLocation

"/tmp"

HomeLocation

"~"

AppLocalDataLocation

"~/.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>"

Path type

Android

iOS

DesktopLocation

"<APPROOT>/files"

"<APPROOT>/Documents/Desktop"

DocumentsLocation

"<USER>/Documents", "<USER>/<APPNAME>/Documents"

"<APPROOT>/Documents"

FontsLocation

"/system/fonts" (not writable)

"<APPROOT>/Library/Fonts"

ApplicationsLocation

not supported (directory not readable)

not supported

MusicLocation

"<USER>/Music", "<USER>/<APPNAME>/Music"

"<APPROOT>/Documents/Music"

MoviesLocation

"<USER>/Movies", "<USER>/<APPNAME>/Movies"

"<APPROOT>/Documents/Movies"

PicturesLocation

"<USER>/Pictures", "<USER>/<APPNAME>/Pictures"

"<APPROOT>/Documents/Pictures", "assets-library://"

TempLocation

"<APPROOT>/cache"

"<APPROOT>/tmp"

HomeLocation

"<APPROOT>/files"

system defined

AppLocalDataLocation

"<APPROOT>/files", "<USER>/<APPNAME>/files"

"<APPROOT>/Library/Application Support"

CacheLocation

"<APPROOT>/cache", "<USER>/<APPNAME>/cache"

"<APPROOT>/Library/Caches"

GenericDataLocation

"<USER>"

"<APPROOT>/Library/Application Support"

RuntimeLocation

"<APPROOT>/cache"

not supported

ConfigLocation

"<APPROOT>/files/settings"

"<APPROOT>/Library/Preferences"

GenericConfigLocation

"<APPROOT>/files/settings" (there is no shared settings)