Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
|
\inmodule QtCore More...
#include <qresource.h>
Public Types | |
enum | Compression { NoCompression , ZlibCompression , ZstdCompression } |
Public Member Functions | |
QResource (const QString &file=QString(), const QLocale &locale=QLocale()) | |
Constructs a QResource pointing to file. | |
~QResource () | |
Releases the resources of the QResource object. | |
void | setFileName (const QString &file) |
Sets a QResource to point to file. | |
QString | fileName () const |
Returns the full path to the file that this QResource represents as it was passed. | |
QString | absoluteFilePath () const |
Returns the real path that this QResource represents, if the resource was found via the QDir::searchPaths() it will be indicated in the path. | |
void | setLocale (const QLocale &locale) |
Sets a QResource to only load the localization of resource to for locale. | |
QLocale | locale () const |
Returns the locale used to locate the data for the QResource. | |
bool | isValid () const |
Returns true if the resource really exists in the resource hierarchy, false otherwise. | |
Compression | compressionAlgorithm () const |
qint64 | size () const |
Returns the size of the stored data backing the resource. | |
const uchar * | data () const |
Returns direct access to a segment of read-only data, that this resource represents. | |
qint64 | uncompressedSize () const |
QByteArray | uncompressedData () const |
QDateTime | lastModified () const |
Static Public Member Functions | |
static bool | registerResource (const QString &rccFilename, const QString &resourceRoot=QString()) |
Registers the resource with the given rccFileName at the location in the resource tree specified by mapRoot, and returns true if the file is successfully opened; otherwise returns false . | |
static bool | unregisterResource (const QString &rccFilename, const QString &resourceRoot=QString()) |
Unregisters the resource with the given rccFileName at the location in the resource tree specified by mapRoot, and returns true if the resource is successfully unloaded and no references exist for the resource; otherwise returns false . | |
static bool | registerResource (const uchar *rccData, const QString &resourceRoot=QString()) |
static bool | unregisterResource (const uchar *rccData, const QString &resourceRoot=QString()) |
Protected Member Functions | |
bool | isDir () const |
Returns true if the resource represents a directory and thus may have children() in it, false if it represents a file. | |
bool | isFile () const |
Returns true if the resource represents a file and thus has data backing it, false if it represents a directory. | |
QStringList | children () const |
Returns a list of all resources in this directory, if the resource represents a file the list will be empty. | |
Protected Attributes | |
QScopedPointer< QResourcePrivate > | d_ptr |
Friends | |
class | QResourceFileEngine |
class | QResourceFileEngineIterator |
\inmodule QtCore
The QResource class provides an interface for reading directly from resources.
\reentrant
QResource is an object that represents a set of data (and possibly children) relating to a single resource entity. QResource gives direct access to the bytes in their raw format. In this way direct access allows reading data without buffer copying or indirection. Indirection is often useful when interacting with the resource entity as if it is a file, this can be achieved with QFile. The data and children behind a QResource are normally compiled into an application/library, but it is also possible to load a resource at runtime. When loaded at run time the resource file will be loaded as one big set of data and then given out in pieces via references into the resource tree.
A QResource can either be loaded with an absolute path, either treated as a file system rooted with a {/} character, or in resource notation rooted with a
{:} character. A relative resource can also be opened which will be found in the list of paths returned by QDir::searchPaths().
A QResource that is representing a file will have data backing it, this data can possibly be compressed, in which case qUncompress() must be used to access the real data; this happens implicitly when accessed through a QFile. A QResource that is representing a directory will have only children and no data.
Definition at line 19 of file qresource.h.
This enum is used by compressionAlgorithm() to indicate which algorithm the RCC tool used to compress the payload.
\value NoCompression Contents are not compressed \value ZlibCompression Contents are compressed using \l{https://zlib.net}{zlib} and can be decompressed using the qUncompress() function. \value ZstdCompression Contents are compressed using \l{Zstandard Site}{zstd}. To decompress, use the {ZSTD_decompress} function from the zstd library.
Enumerator | |
---|---|
NoCompression | |
ZlibCompression | |
ZstdCompression |
Definition at line 22 of file qresource.h.
Constructs a QResource pointing to file.
locale is used to load a specific localization of a resource data.
Definition at line 507 of file qresource.cpp.
QResource::~QResource | ( | ) |
Releases the resources of the QResource object.
Definition at line 517 of file qresource.cpp.
QString QResource::absoluteFilePath | ( | ) | const |
Returns the real path that this QResource represents, if the resource was found via the QDir::searchPaths() it will be indicated in the path.
Definition at line 582 of file qresource.cpp.
|
protected |
Returns a list of all resources in this directory, if the resource represents a file the list will be empty.
Definition at line 755 of file qresource.cpp.
QResource::Compression QResource::compressionAlgorithm | ( | ) | const |
Returns the compression type that this resource is compressed with, if any. If it is not compressed, this function returns QResource::NoCompression.
If this function returns QResource::ZlibCompression, you may decompress the data using the qUncompress() function. Up until Qt 5.13, this was the only possible compression algorithm.
If this function returns QResource::ZstdCompression, you need to use the Zstandard library functions ({<zstd.h>} header). Qt does not provide a wrapper.
See \l{http://facebook.github.io/zstd/zstd_manual.html}{Zstandard manual}.
Definition at line 629 of file qresource.cpp.
const uchar * QResource::data | ( | ) | const |
Returns direct access to a segment of read-only data, that this resource represents.
If the resource is compressed, the data returned is also compressed. The caller must then decompress the data or use uncompressedData(). If the resource is a directory, nullptr
is returned.
Definition at line 678 of file qresource.cpp.
QString QResource::fileName | ( | ) | const |
Returns the full path to the file that this QResource represents as it was passed.
Definition at line 568 of file qresource.cpp.
|
protected |
Returns true
if the resource represents a directory and thus may have children() in it, false if it represents a file.
Definition at line 741 of file qresource.cpp.
|
inlineprotected |
Returns true
if the resource represents a file and thus has data backing it, false if it represents a directory.
Definition at line 57 of file qresource.h.
bool QResource::isValid | ( | ) | const |
Returns true
if the resource really exists in the resource hierarchy, false otherwise.
Definition at line 595 of file qresource.cpp.
QDateTime QResource::lastModified | ( | ) | const |
Returns the date and time when the file was last modified before packaging into a resource.
Definition at line 727 of file qresource.cpp.
QLocale QResource::locale | ( | ) | const |
Returns the locale used to locate the data for the QResource.
Definition at line 540 of file qresource.cpp.
|
static |
Registers the resource with the given rccFileName at the location in the resource tree specified by mapRoot, and returns true
if the file is successfully opened; otherwise returns false
.
Definition at line 1255 of file qresource.cpp.
|
static |
Registers the resource with the given rccData at the location in the resource tree specified by mapRoot, and returns true
if the file is successfully opened; otherwise returns false
.
Definition at line 1324 of file qresource.cpp.
Sets a QResource to point to file.
file can either be absolute, in which case it is opened directly, if relative then the file will be tried to be found in QDir::searchPaths().
Definition at line 554 of file qresource.cpp.
Sets a QResource to only load the localization of resource to for locale.
If a resource for the specific locale is not found then the C locale is used.
Definition at line 529 of file qresource.cpp.
qint64 QResource::size | ( | ) | const |
Returns the size of the stored data backing the resource.
If the resource is compressed, this function returns the size of the compressed data. See uncompressedSize() for the uncompressed size.
Definition at line 645 of file qresource.cpp.
QByteArray QResource::uncompressedData | ( | ) | const |
Returns the resource data, decompressing it first, if the data was stored compressed. If the resource is a directory or an error occurs while decompressing, a null QByteArray is returned.
Definition at line 698 of file qresource.cpp.
qint64 QResource::uncompressedSize | ( | ) | const |
Returns the size of the data in this resource. If the data was not compressed, this function returns the same as size(). If it was, then this function extracts the size of the original uncompressed data from the stored stream.
Definition at line 662 of file qresource.cpp.
|
static |
Unregisters the resource with the given rccFileName at the location in the resource tree specified by mapRoot, and returns true
if the resource is successfully unloaded and no references exist for the resource; otherwise returns false
.
Definition at line 1287 of file qresource.cpp.
|
static |
Unregisters the resource with the given rccData at the location in the resource tree specified by mapRoot, and returns true
if the resource is successfully unloaded and no references exist into the resource; otherwise returns false
.
Definition at line 1356 of file qresource.cpp.
|
friend |
Definition at line 54 of file qresource.h.
|
friend |
Definition at line 55 of file qresource.h.
|
protected |
Definition at line 61 of file qresource.h.