QStandardPathsclass provides methods for accessing standard paths. 更多 …
New in version 5.0.
def
displayName
(type)
def
enableTestMode
(testMode)
def
findExecutable
(executableName[, paths=list()])
def
isTestModeEnabled
()
def
locate
(type, fileName[, options=QStandardPaths.LocateFile])
def
locateAll
(type, fileName[, options=QStandardPaths.LocateFile])
def
setTestModeEnabled
(testMode)
def
standardLocations
(type)
def
writableLocation
(type)
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.
PySide2.QtCore.QStandardPaths.
StandardLocation
¶
This enum describes the different locations that can be queried using methods such as
writableLocation
,
standardLocations
,和
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
.
|
常量 |
描述 |
|---|---|
|
QStandardPaths.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.DocumentsLocation |
Returns the directory containing user document files. This is a generic value. The returned path is never empty. |
|
QStandardPaths.FontsLocation |
Returns the directory containing user’s fonts. This is a generic value. Note that installing fonts may require additional, platform-specific operations. |
|
QStandardPaths.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. |
|
QStandardPaths.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. |
|
QStandardPaths.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. |
|
QStandardPaths.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. |
|
QStandardPaths.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. |
|
QStandardPaths.HomeLocation |
Returns the user’s home directory (the same as
|
|
QStandardPaths.DataLocation |
Returns the same value as . This enumeration value is deprecated. Using is preferable since on Windows, the roaming path is recommended. |
|
QStandardPaths.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. |
|
QStandardPaths.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. |
|
QStandardPaths.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. |
|
QStandardPaths.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. |
|
QStandardPaths.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. |
|
QStandardPaths.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. |
|
QStandardPaths.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. |
|
QStandardPaths.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 . 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.AppLocalDataLocation |
Returns the local settings path on the Windows operating system. On all other platforms, it returns the same value as . This enum value was added in Qt 5.4. |
|
QStandardPaths.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. |
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.
|
路径类型 |
macOS |
Windows |
|
“~/Desktop” |
“C:/Users/<USER>/Desktop” |
|
|
“~/Documents” |
“C:/Users/<USER>/Documents” |
|
|
“/System/Library/Fonts” (not writable) |
“C:/Windows/Fonts” (not writable) |
|
|
“/Applications” (not writable) |
“C:/Users/<USER>/AppData/Roaming/Microsoft/Windows/Start Menu/Programs” |
|
|
“~/Music” |
“C:/Users/<USER>/Music” |
|
|
“~/Movies” |
“C:/Users/<USER>/Videos” |
|
|
“~/Pictures” |
“C:/Users/<USER>/Pictures” |
|
|
randomly generated by the OS |
“C:/Users/<USER>/AppData/Local/Temp” |
|
|
“~” |
“C:/Users/<USER>” |
|
|
“~/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>” |
|
|
“~/Library/Caches/<APPNAME>”, “/Library/Caches/<APPNAME>” |
“C:/Users/<USER>/AppData/Local/<APPNAME>/cache” |
|
|
“~/Library/Application Support”, “/Library/Application Support” |
“C:/Users/<USER>/AppData/Local”, “C:/ProgramData”, “<APPDIR>”, “<APPDIR>/data” |
|
|
“~/Library/Application Support” |
“C:/Users/<USER>” |
|
|
“~/Library/Preferences” |
“C:/Users/<USER>/AppData/Local/<APPNAME>”, “C:/ProgramData/<APPNAME>” |
|
|
“~/Library/Preferences” |
“C:/Users/<USER>/AppData/Local”, “C:/ProgramData” |
|
|
“~/Downloads” |
“C:/Users/<USER>/Documents” |
|
|
“~/Library/Caches”, “/Library/Caches” |
“C:/Users/<USER>/AppData/Local/cache” |
|
|
“~/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>” |
|
|
“~/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>” |
|
|
“~/Library/Preferences/<APPNAME>” |
“C:/Users/<USER>/AppData/Local/<APPNAME>”, “C:/ProgramData/<APPNAME>” |
|
路径类型 |
Linux |
|
“~/Desktop” |
|
|
“~/Documents” |
|
|
“~/.fonts”, “~/.local/share/fonts”, “/usr/local/share/fonts”, “/usr/share/fonts” |
|
|
“~/.local/share/applications”, “/usr/local/share/applications”, “/usr/share/applications” |
|
|
“~/Music” |
|
|
“~/Videos” |
|
|
“~/Pictures” |
|
|
“/tmp” |
|
|
“~” |
|
|
“~/.local/share/<APPNAME>”, “/usr/local/share/<APPNAME>”, “/usr/share/<APPNAME>” |
|
|
“~/.cache/<APPNAME>” |
|
|
“~/.local/share”, “/usr/local/share”, “/usr/share” |
|
|
“/run/user/<USER>” |
|
|
“~/.config”, “/etc/xdg” |
|
|
“~/.config”, “/etc/xdg” |
|
|
“~/Downloads” |
|
|
“~/.cache” |
|
|
“~/.local/share/<APPNAME>”, “/usr/local/share/<APPNAME>”, “/usr/share/<APPNAME>” |
|
|
“~/.local/share/<APPNAME>”, “/usr/local/share/<APPNAME>”, “/usr/share/<APPNAME>” |
|
|
“~/.config/<APPNAME>”, “/etc/xdg/<APPNAME>” |
|
路径类型 |
Android |
iOS |
|
“<APPROOT>/files” |
“<APPROOT>/Documents/Desktop” |
|
|
“<USER>/Documents”, “<USER>/<APPNAME>/Documents” |
“<APPROOT>/Documents” |
|
|
“/system/fonts” (not writable) |
“<APPROOT>/Library/Fonts” |
|
|
not supported (directory not readable) |
not supported |
|
|
“<USER>/Music”, “<USER>/<APPNAME>/Music” |
“<APPROOT>/Documents/Music” |
|
|
“<USER>/Movies”, “<USER>/<APPNAME>/Movies” |
“<APPROOT>/Documents/Movies” |
|
|
“<USER>/Pictures”, “<USER>/<APPNAME>/Pictures” |
“<APPROOT>/Documents/Pictures”, “assets-library://” |
|
|
“<APPROOT>/cache” |
“<APPROOT>/tmp” |
|
|
“<APPROOT>/files” |
system defined |
|
|
“<APPROOT>/files”, “<USER>/<APPNAME>/files” |
“<APPROOT>/Library/Application Support” |
|
|
“<APPROOT>/cache”, “<USER>/<APPNAME>/cache” |
“<APPROOT>/Library/Caches” |
|
|
“<USER>” |
“<APPROOT>/Documents” |
|
|
“<APPROOT>/cache” |
not supported |
|
|
“<APPROOT>/files/settings” |
“<APPROOT>/Library/Preferences” |
|
|
“<APPROOT>/files/settings” (there is no shared settings) |
“<APPROOT>/Library/Preferences” |
|
|
“<USER>/Downloads”, “<USER>/<APPNAME>/Downloads” |
“<APPROOT>/Documents/Downloads” |
|
|
“<APPROOT>/cache” (there is no shared cache) |
“<APPROOT>/Library/Caches” |
|
|
“<APPROOT>/files”, “<USER>/<APPNAME>/files” |
“<APPROOT>/Library/Application Support” |
|
|
“<APPROOT>/files/settings” |
“<APPROOT>/Library/Preferences/<APPNAME>” |
|
|
“<APPROOT>/files”, “<USER>/<APPNAME>/files” |
“<APPROOT>/Library/Application Support” |
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.
注意
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
writableLocation
or
standardLocations
.
注意
On iOS, if you do pass
QStandardPaths::standardLocations(QStandardPaths::PicturesLocation).last()
as argument to
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.
PySide2.QtCore.QStandardPaths.
LocateOption
¶
This enum describes the different flags that can be used for controlling the behavior of
locate
and
locateAll
.
|
常量 |
描述 |
|---|---|
|
QStandardPaths.LocateFile |
只返回文件 |
|
QStandardPaths.LocateDirectory |
只返回目录 |
PySide2.QtCore.QStandardPaths.
displayName
(
type
)
¶
type
–
StandardLocation
unicode
Returns a localized display name for the given location
type
or an empty
QString
if no relevant location can be found.
PySide2.QtCore.QStandardPaths.
enableTestMode
(
testMode
)
¶
testMode
–
bool
注意
此函数被弃用。
PySide2.QtCore.QStandardPaths.
findExecutable
(
executableName
[
,
paths=list()
]
)
¶
executableName – unicode
paths – 字符串列表
unicode
Finds the executable named
executableName
以指定
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 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 .
注意
On Windows, the usual executable extensions (from the PATHEXT environment variable) are automatically appended. For example, the (“foo”) call finds
foo.exe
or
foo.bat
if present.
Returns the absolute file path to the executable, or an empty string if not found.
PySide2.QtCore.QStandardPaths.
isTestModeEnabled
(
)
¶
bool
PySide2.QtCore.QStandardPaths.
locate
(
type
,
fileName
[
,
options=QStandardPaths.LocateFile
]
)
¶
type
–
StandardLocation
fileName – unicode
options
–
LocateOptions
unicode
Finds a file or directory called
fileName
in the standard locations for
type
.
options
flag lets you specify whether to look for files or directories. By default, this flag is set to
LocateFile
.
Returns the absolute path to the first file or directory found, otherwise returns an empty string.
PySide2.QtCore.QStandardPaths.
locateAll
(
type
,
fileName
[
,
options=QStandardPaths.LocateFile
]
)
¶
type
–
StandardLocation
fileName – unicode
options
–
LocateOptions
字符串列表
Finds all files or directories by the name,
fileName
, in the standard locations for
type
.
options
flag lets you specify whether to look for files or directories. By default, this flag is set to
LocateFile
.
Returns the list of all the files that were found.
PySide2.QtCore.QStandardPaths.
setTestModeEnabled
(
testMode
)
¶
testMode
–
bool
若
testMode
is
true
, this enables a special “test mode” in
QStandardPaths
, which changes writable locations to point to test directories. This prevents auto tests from reading or writing to the current user’s configuration.
It affects the locations into which test programs might write files:
GenericDataLocation
,
DataLocation
,
ConfigLocation
,
GenericConfigLocation
,
AppConfigLocation
,
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
,和
XDG_CACHE_HOME
is set to
~/.qttest/cache
.
On macOS, data goes to
~/.qttest/Application
支持
, cache goes to
~/.qttest/Cache
, and config goes to
~/.qttest/Preferences
.
On Windows, everything goes to a “qttest” directory under
%APPDATA%
.
PySide2.QtCore.QStandardPaths.
standardLocations
(
type
)
¶
type
–
StandardLocation
字符串列表
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.
另请参阅
PySide2.QtCore.QStandardPaths.
writableLocation
(
type
)
¶
type
–
StandardLocation
unicode
Returns the directory where files of
type
should be written to, or an empty string if the location cannot be determined.
注意
The storage location returned may not exist; that is, it may need to be created by the system or the user.