QrcParser Class
class Utils::QrcParserThe QrcParser class parses one or more QRC files and keeps their content cached. More...
Header: | #include <QrcParser> |
Public Types
Public Functions
void | collectFilesAtPath(const QString &path, QStringList *res, const QLocale *locale = nullptr) const |
void | collectFilesInPath(const QString &path, QMap<QString, QStringList> *res, bool addDirs = false, const QLocale *locale = nullptr) const |
void | collectResourceFilesForSourceFile(const QString &sourceFile, QStringList *res, const QLocale *locale = nullptr) const |
QStringList | errorMessages() const |
QString | 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 QString &path, const QString &contents) |
Static Public Members
QString | normalizedQrcDirectoryPath(const QString &path) |
QString | normalizedQrcFilePath(const QString &path) |
Utils::QrcParser::Ptr | parseQrcFile(const QString &path, const QString &contents) |
QString | qrcDirectoryPathForQrcFilePath(const QString &file) |
Detailed Description
A Qt resource collection (QRC) contains files read from the file system but organized in a possibly different way. To easily describe that with a simple structure, we use a map from QRC paths to the paths in the filesystem. By using a map, we can easily find all QRC paths that start with a given prefix, and thus loop on a QRC directory.
QRC files also support languages, which are mapped to a prefix of the QRC path. For example, the French /image/bla.png (lang=fr) will have the path fr/image/bla.png
. The empty language represents the default resource. Languages are looked up using the locale uiLanguages() property
For a single QRC, a given path maps to a single file, but when one has multiple (platform-specific and mutually exclusive) QRC files, multiple files match, so QStringList are used.
Especially, the collect*
functions are thought of as low level interface.
Member Type Documentation
[alias]
QrcParser::ConstPtr
Represents constant pointers.
[alias]
QrcParser::Ptr
Represents pointers.
Member Function Documentation
void QrcParser::collectFilesAtPath(const QString &path, QStringList *res, const QLocale *locale = nullptr) const
Adds the file system paths for the given QRC path to res.
If locale is null, all possible files are added. Otherwise, just the first one that matches the locale is added.
void QrcParser::collectFilesInPath(const QString &path, QMap<QString, QStringList> *res, bool addDirs = false, const QLocale *locale = nullptr) const
Adds the directory contents of the given QRC path to res if addDirs is set to true
.
Adds the QRC filename to file system path associations contained in the given path to res. If addDirs() is true
, directories are also added.
If locale is null, all possible files are added. Otherwise, just the first file with a matching the locale is added.
void QrcParser::collectResourceFilesForSourceFile(const QString &sourceFile, QStringList *res, const QLocale *locale = nullptr) const
Adds the resource files from the QRC file sourceFile to res.
If locale is null, all possible files are added. Otherwise, just the first file with a matching the locale is added.
QStringList QrcParser::errorMessages() const
Returns the errors found while parsing.
QString QrcParser::firstFileAtPath(const QString &path, const QLocale &locale) const
Returns the file system path of the first (active) file at the given QRC path and locale.
bool QrcParser::hasDirAtPath(const QString &path, const QLocale *locale = nullptr) const
Returns true
if path is a non-empty directory and matches locale.
bool QrcParser::isValid() const
Indicates whether the QRC contents are valid.
Returns an error if the QRC is empty.
QStringList QrcParser::languages() const
Returns all languages used in this QRC.
[static]
QString QrcParser::normalizedQrcDirectoryPath(const QString &path)
Returns the path to a directory normalized to path in a QRC resource by dropping the qrc:/
or :
and any extra slashes at the beginning, and by ensuring that the path ends with a slash
[static]
QString QrcParser::normalizedQrcFilePath(const QString &path)
Normalizes the path to a file in a QRC resource by dropping the qrc:/
or :
and any extra slashes in the beginning.
bool QrcParser::parseFile(const QString &path, const QString &contents)
Parses the QRC file at path. If contents is not empty, it is used as the file contents instead of reading it from the file system.
Returns whether the parsing succeeded.
See also errorMessages() and parseQrcFile().
[static]
Utils::QrcParser::Ptr QrcParser::parseQrcFile(const QString &path, const QString &contents)
Returns the contents of the QRC file at path.
[static]
QString QrcParser::qrcDirectoryPathForQrcFilePath(const QString &file)
Returns the QRC directory path for file.
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.