Utils::QrcParser Class
class Utils::QrcParserQrcParser 类用于解析一个或多个 QRC 文件,并将它们的内容保存在缓存中。更多内容...
| Header: | #include <QrcParser> |
公共类型
公共函数
| void | collectFilesAtPath(const QString &path, Utils::FilePaths *res, const QLocale *locale = nullptr) const |
| void | collectFilesInPath(const QString &path, QMap<QString, Utils::FilePaths> *res, bool addDirs = false, const QLocale *locale = nullptr) const |
| void | collectResourceFilesForSourceFile(const Utils::FilePath &sourceFile, QStringList *res, const QLocale *locale = nullptr) const |
| QStringList | errorMessages() const |
| Utils::FilePath | firstFileAtPath(const QString &path, const QLocale &locale) const |
| bool | hasDirAtPath(const QString &path, const QLocale *locale = nullptr) const |
| bool | isValid() const |
| QStringList | languages() const |
| bool | parseFile(const Utils::FilePath &path, const QString &contents) |
静态公共成员
| QString | normalizedQrcDirectoryPath(const QString &path) |
| QString | normalizedQrcFilePath(const QString &path) |
| Utils::QrcParser::Ptr | parseQrcFile(const Utils::FilePath &path, const QString &contents) |
| QString | qrcDirectoryPathForQrcFilePath(const QString &file) |
详细描述
Qt 资源集合 (QRC)包含从文件系统读取的文件,但组织方式可能有所不同。 为了用简单的结构来描述这一点,我们使用了一个从 QRC 路径到文件系统路径的映射。通过使用映射,我们可以轻松地找到所有以给定前缀开头的 QRC 路径,从而遍历 QRC 目录。
QRC 文件还支持语言,这些语言被映射到 QRC 路径的前缀上。例如,法语文件 /image/bla.png (lang=fr) 的路径为fr/image/bla.png 。空语言代表默认资源。语言可通过 locale 的 uiLanguages() 属性进行查询
对于单个 QRC,给定路径映射到单个文件;但当存在多个(平台特定且互斥的)QRC 文件时,会有多个文件匹配,因此会使用QStringList 。
特别是,collect* 函数被视为低级接口。
成员函数文档
void QrcParser::collectFilesAtPath(const QString &path, Utils::FilePaths *res, const QLocale *locale = nullptr) const
将给定 QRC 的文件系统路径path 添加到res 中。
如果locale 为空,则添加所有可能的文件。否则,仅添加第一个与该语言环境匹配的文件。
void QrcParser::collectFilesInPath(const QString &path, QMap<QString, Utils::FilePaths> *res, bool addDirs = false, const QLocale *locale = nullptr) const
如果将addDirs 设置为true ,则将给定QRC文件path 中的目录内容添加到res 中。
将 QRC 文件名添加到给定path 中包含的文件系统路径关联中,这些关联位于res 中。如果 addDirs() 的值为true ,则目录也会被添加。
如果locale 为null,则添加所有可能的文件。否则,仅添加第一个与该语言环境匹配的文件。
void QrcParser::collectResourceFilesForSourceFile(const Utils::FilePath &sourceFile, QStringList *res, const QLocale *locale = nullptr) const
将 QRC 文件sourceFile 中的资源文件添加到res 中。
如果locale 为空,则添加所有可能的文件。否则,仅添加第一个与该语言环境匹配的文件。
QStringList QrcParser::errorMessages() const
返回解析过程中发现的错误。
Utils::FilePath QrcParser::firstFileAtPath(const QString &path, const QLocale &locale) const
返回给定 QRC(path 和locale )处第一个(活动)文件的文件系统路径。
bool QrcParser::hasDirAtPath(const QString &path, const QLocale *locale = nullptr) const
如果path 是一个非空目录且与locale 匹配,则返回true 。
bool QrcParser::isValid() const
指示QRC内容是否有效。
如果 QRC 为空,则返回错误。
QStringList QrcParser::languages() const
返回此 QRC 中使用的所有语言。
[static] QString QrcParser::normalizedQrcDirectoryPath(const QString &path)
返回 QRC 资源中一个目录的路径,该路径已规范化为path 格式:移除qrc:/ 或: 以及开头多余的斜杠,并确保路径以斜杠结尾
[static] QString QrcParser::normalizedQrcFilePath(const QString &path)
将path 规范化为 QRC 资源中的文件,方法是删除qrc:/ 或: 以及开头处的所有多余斜杠。
bool QrcParser::parseFile(const Utils::FilePath &path, const QString &contents)
解析位于path 的 QRC 文件。如果contents 不为空,则直接使用该值作为文件内容,而非从文件系统中读取。
返回解析是否成功。
另请参阅 errorMessages() 和parseQrcFile()。
[static] Utils::QrcParser::Ptr QrcParser::parseQrcFile(const Utils::FilePath &path, const QString &contents)
返回位于path 的 QRC 文件的contents 。
[static] QString QrcParser::qrcDirectoryPathForQrcFilePath(const QString &file)
返回file 的QRC目录路径。
Copyright © The Qt Company Ltd. and other contributors. 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.