- Extending Qt Creator Manual
- QtCreator
- QrcParser
- Extending Qt Creator Manual 13.0.0

# QrcParser Class

class Utils::QrcParser

The QrcParser class parses one or more QRC files and keeps their content cached. More...

Header: | #include <QrcParser>

- List of all members, including inherited members

## Public Types

| ConstPtr
| Ptr

## Public Functions

void | collectFilesAtPath(const class QString &path, class QStringList *res, const QLocale *locale = nullptr) const
void | collectFilesInPath(const class QString &path, int *res, bool addDirs = false, const QLocale *locale = nullptr) const
void | collectResourceFilesForSourceFile(const class QString &sourceFile, class QStringList *res, const QLocale *locale = nullptr) const
class QStringList | errorMessages() const
class QString | firstFileAtPath(const class QString &path, const QLocale &locale) const
bool | hasDirAtPath(const class QString &path, const QLocale *locale = nullptr) const
bool | isValid() const
class QStringList | languages() const
bool | parseFile(const class QString &path, const class QString &contents)

## Static Public Members

class QString | normalizedQrcDirectoryPath(const class QString &path)
class QString | normalizedQrcFilePath(const class QString &path)
Utils::QrcParser::Ptr | parseQrcFile(const class QString &path, const class QString &contents)
class QString | qrcDirectoryPathForQrcFilePath(const class 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 class QString &path, class 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 class QString &path, int *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 class QString &sourceFile, class 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.

### class QStringList QrcParser::errorMessages() const

Returns the errors found while parsing.

### class QString QrcParser::firstFileAtPath(const class 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 class 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.

### class QStringList QrcParser::languages() const

Returns all languages used in this QRC.

### `[static]` class QString QrcParser::normalizedQrcDirectoryPath(const class 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]` class QString QrcParser::normalizedQrcFilePath(const class 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 class QString &path, const class 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 class QString &path, const class QString &contents)

Returns the contents of the QRC file at path.

### `[static]` class QString QrcParser::qrcDirectoryPathForQrcFilePath(const class QString &file)

Returns the QRC directory path for file.