本页内容

StandardPaths QML Type

提供对标准系统路径的访问。更多...

Import Statement: import Qt.labs.platform
Inherits:

QtObject

Status: Deprecated since 6.4

自 Qt Labs Platform 6.4 起,此类型已被废弃。我们强烈建议不要在新代码中使用它。

方法

详细说明

请改用 QtCore::StandardPaths。

StandardPaths 单例类提供了用于查询系统标准路径的方法。这些标准路径通常与FileDialog 和FolderDialog 类型配合使用时最为有用。

FileDialog {
    folder: StandardPaths.writableLocation(StandardPaths.DocumentsLocation)
}

注意: Qt.labs 模块中的类型在未来版本中不保证保持兼容性。

另请参阅 QtCore::StandardPaths 、FileDialog 、FolderDialog 和QStandardPaths 。

方法文档

string displayName(StandardLocation type)

返回给定位置type 的本地化显示名称;如果找不到相关位置,则返回空QString 。

另请参阅 QStandardPaths::displayName()。

url findExecutable(string executableName, list<string> paths)

在指定的paths 中查找名为executableName 的可执行文件;如果paths 为空,则在系统路径中查找。

在大多数操作系统中,系统路径由PATH 环境变量决定。可在paths参数中设置用于搜索可执行文件的目录。 若要在用户自定义路径和系统路径中同时进行搜索,请调用两次 findExecutable 函数:一次设置 paths 参数,一次留空。为保持那些行为取决于调用名称的可执行文件的行为一致性,系统不会解析符号链接。

注意:在 Windows系统上 ,会自动追加常见的可执行文件扩展名(来自 PATHEXT 环境变量)。例如,findExecutable("foo") 调用会查找foo.exe 或foo.bat (如果存在)。

返回可执行文件的绝对文件路径;若未找到,则返回空字符串。

如果给定的executableName 是指向可执行文件的绝对路径,则返回其干净路径。

另请参阅 QStandardPaths::findExecutable()。

url locate(StandardLocation type, string fileName, LocateOptions options)

在type 的标准位置中查找名为fileName 的文件或目录。

options 标志用于指定要查找的是文件还是目录。默认情况下,该标志设置为LocateFile 。

返回找到的第一个文件或目录的绝对路径,否则返回一个空字符串。

另请参阅 QStandardPaths::locate()。

list<url> locateAll(StandardLocation type, string fileName, LocateOptions options)

在type 的标准位置中,查找名称为fileName 的所有文件或目录。

options 标志用于指定搜索文件还是目录。默认情况下,该标志设置为LocateFile 。

返回所有找到的文件列表。

另请参阅 QStandardPaths::locateAll()。

void setTestModeEnabled(bool testMode)

如果testMode 的值为true ,则会在QStandardPaths 中启用一种特殊的“测试模式”,该模式会将可写位置更改为指向测试目录。这可以防止自动测试读取或写入当前用户的配置。

这会影响测试程序可能写入文件的位置:GenericDataLocation 、AppDataLocation 、ConfigLocation 、GenericConfigLocation 、AppConfigLocation 、StateLocation 、GenericStateLocation 、GenericCacheLocation 以及CacheLocation 。其他位置不受影响。

在 Unix 系统上,XDG_DATA_HOME 设置为~/.qttest/share ,XDG_CONFIG_HOME 设置为~/.qttest/config ,XDG_STATE_HOME 设置为~/.qttest/state ,XDG_CACHE_HOME 设置为~/.qttest/cache 。

在 macOS 上,数据存储在~/.qttest/Application Support ,缓存存储在~/.qttest/Cache ,配置文件存储在~/.qttest/Preferences 。

在 Windows 系统中,所有内容都存放在%APPDATA% 下的“qttest”目录中。

另请参阅 QStandardPaths::setTestModeEnabled()。

list<url> standardLocations(StandardLocation type)

返回所有包含type 类型文件的目录。

目录列表按优先级从高到低排序,如果能够确定,则以writableLocation() 为首。如果未为该类型定义任何位置,则该列表为空。

另请参阅 QStandardPaths::standardLocations()。

url writableLocation(StandardLocation type)

返回type 文件应写入的目录,如果无法确定该位置,则返回空字符串。

注意: 返回的存储位置可能不存在;也就是说,系统或用户可能需要创建该目录 。

另请参阅 QStandardPaths::writableLocation()。

© 2026 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.