Format:Qt resource
| On this wiki | Facts · Code · Notes · Topics |
|---|
Qt's embedded-resource format: rcc compiles a .qrc list into three arrays (qt_resource_struct tree, qt_resource_name names, qt_resource_data payloads) registered with qRegisterResourceData, or into a standalone .rcc file starting 'qres'. Files may be stored raw, zlib-compressed (4-byte size prefix) or Zstandard-compressed.
Overview
rcc (Resource Compiler) reads .qrc XML and writes C++ (qrc_<name>.cpp), Python (PySide), or a binary .rcc file. In compiled programs the data is three byte arrays and an initializer that calls qRegisterResourceData(version, struct, name, data) from a static constructor; at runtime files are opened as :/prefix/file. Qt itself only supports the trees below; format versions 1 to 3 exist (rcc default is 3).
Binary .rcc header (20 or 24 bytes)
All values are big-endian.
| Offset | Size | Field |
|---|---|---|
| 0 | 4 | magic qres (71 72 65 73)
|
| 4 | 4 | format version (1, 2 or 3) |
| 8 | 4 | offset of the tree (qt_resource_struct) |
| 12 | 4 | offset of the data (qt_resource_data) |
| 16 | 4 | offset of the names (qt_resource_name) |
| 20 | 4 | overall flags (version 3 only): 1 some zlib data, 4 some Zstandard data |
| The offsets are patched after writing; the three blocks follow in the order data, names, tree. In compiled programs there is no header, only the three arrays. |
Tree (qt_resource_struct)
Nodes are fixed-size, referenced by index (offset = index * node size; node size 14 bytes in version 1, 22 bytes in versions 2 and 3). Node 0 is the root directory. All integers big-endian.
- Directory node: name offset (4, into the names block), flags (2; bit 0x02 = directory), child count (4), first child node index (4).
- File node: name offset (4), flags (2), territory (country) code (2), language code (2), data offset (4, into the data block). Version 2+ appends an 8-byte last-modified time in milliseconds since the Unix epoch (0 if unknown;
SOURCE_DATE_EPOCHorQT_RCC_SOURCE_DATE_OVERRIDEoverrides it for reproducible builds). - File flags: 0x01 compressed with zlib, 0x02 directory, 0x04 compressed with Zstandard.
- Children of one directory are stored consecutively and sorted by the hash of their name (ascending) for binary search.
Names (qt_resource_name)
Each distinct name is stored once: 2-byte length in UTF-16 code units, 4-byte hash, then the name as UTF-16 big-endian. A node's name offset points at the length field. The hash is Qt's qt_hash: h = 0; for each UTF-16 unit c: h = (h << 4) + c; h ^= (h & 0xF0000000) >> 23; end: h &= 0x0FFFFFFF. Compute it to find a file by name, or to verify the parse.
Data (qt_resource_data)
Each blob is a 4-byte big-endian length followed by that many bytes. Identical files are deduplicated by content. If the file flag is 0x01, the blob is qCompress output: a 4-byte big-endian uncompressed size followed by a standard zlib stream (see Format:Zlib stream). If 0x04, the blob is a Zstandard frame (Format:Zstandard), with the uncompressed size in the frame. rcc keeps the compressed form only if it saves at least the threshold percentage of the original size (--threshold, default 70, from rcc.cpp CONSTANT_COMPRESSTHRESHOLD_DEFAULT); otherwise the file is stored raw, so small or already compressed files (PNG, JPEG) are usually uncompressed in the blob.
Finding resources in an executable
- Look for names block as UTF-16BE strings preceded by 2-byte lengths, for
qt_resource_data/qt_resource_struct/qt_resource_namesymbols, for the exported callqRegisterResourceData/qUnregisterResourceData, or forqResourceFeatureZlib/qResourceFeatureZstd. - The struct block starts with the root directory node: name offset 0, flags 0x0002, child count, first child offset 1 (hex
00 00 00 00 00 02 <count:4> 00 00 00 01). - Contents are usually plain text (QML, JSON, SVG, stylesheets), images (PNG/JPEG),
.qmtranslation files and fonts. QML may be precompiled (qmlcachegen units). - Extracting is a parse of the tree; you do not need Qt. Use Format:Zlib stream/Format:Zstandard decoders for compressed blobs.
Related
Library:Qt, Library:Qt/Meta-object data
Code & repositories
- https://github.com/qt/qtbase @
7faa468198d1d631452db7e5cbfab203cecbdee2· license: LGPL-3.0-only OR GPL-3.0-only (declared by the contributor; GitHub's detector did not recognize a license file)
QtCore, moc and rcc sources: meta-object layout, revisions, resource tree format.
Tested on: source read, not run: source reading · checked 2026-10-18
Evidence & references
- qtbase commit 7faa468198d1d631452db7e5cbfab203cecbdee2:
src/tools/rcc/rcc.cpplines 72-78 (flags), 185-231 (tree nodes), 380-392 (blob length), 422-462 (names), 1180-1196 (header), 1323-1400 (tree order and hash sorting), 1580-1612 (binary header patching);src/tools/rcc/main.cpplines 209-217 (format versions 1-3);src/corelib/io/qresource.cppline 124 (node size 14 + 8);src/corelib/tools/qhash.cpplines 1087-1096 (qt_hash). - Unverified: the 70 percent default compression threshold and the territory/language field naming; check
main.cpp.