The QResource class provides an interface for reading directly from resources. More...
#include <QResource>
Note: All functions in this class are reentrant.
This class was introduced in Qt 4.2.
QResource ( const QString & file = QString(), const QLocale & locale = QLocale() ) | |
~QResource () | |
QString | absoluteFilePath () const |
const uchar * | data () const |
QString | fileName () const |
bool | isCompressed () const |
bool | isValid () const |
QLocale | locale () const |
void | setFileName ( const QString & file ) |
void | setLocale ( const QLocale & locale ) |
qint64 | size () const |
bool | registerResource ( const QString & rccFileName, const QString & mapRoot = QString() ) |
bool | registerResource ( const uchar * rccData, const QString & mapRoot = QString() ) |
bool | unregisterResource ( const QString & rccFileName, const QString & mapRoot = QString() ) |
bool | unregisterResource ( const uchar * rccData, const QString & mapRoot = QString() ) |
QStringList | children () const |
bool | isDir () const |
bool | isFile () const |
The QResource class provides an interface for reading directly from resources.
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.
A resource can be left out of an application's binary and loaded when it is needed at run-time by using the registerResource() function. The resource file passed into registerResource() must be a binary resource as created by rcc. Further information about binary resources can be found in The Qt Resource System documentation.
This can often be useful when loading a large set of application icons that may change based on a setting, or that can be edited by a user and later recreated. The resource is immediately loaded into memory, either as a result of a single file read operation, or as a memory mapped file.
This approach can prove to be a significant performance gain as only a single file will be loaded, and pieces of data will be given out via the path requested in setFileName().
The unregisterResource() function removes a reference to a particular file. If there are QResources that currently reference resources related to the unregistered file, they will continue to be valid but the resource file itself will be removed from the resource roots, and thus no further QResource can be created pointing into this resource data. The resource itself will be unmapped from memory when the last QResource that points to it is destroyed.
See also The Qt Resource System, QFile, QDir, and QFileInfo.
Constructs a QResource pointing to file. locale is used to load a specific localization of a resource data.
See also QFileInfo, QDir::searchPaths(), setFileName(), and setLocale().
Releases the resources of the QResource object.
Returns the real path that this QResource represents, if the resource was found via the QDir::searchPaths() it will be indicated in the path.
See also fileName().
Returns a list of all resources in this directory, if the resource represents a file the list will be empty.
See also isDir().
Returns direct access to a read only segment of data that this resource represents. If the resource is compressed the data returns is compressed and qUncompress() must be used to access the data. If the resource is a directory 0 is returned.
See also size(), isCompressed(), and isFile().
Returns the full path to the file that this QResource represents as it was passed.
See also setFileName() and absoluteFilePath().
Returns true if the resource represents a file and the data backing it is in a compressed format, false otherwise.
Returns true if the resource represents a directory and thus may have children() in it, false if it represents a file.
See also isFile().
Returns true if the resource represents a file and thus has data backing it, false if it represents a directory.
See also isDir().
Returns true if the resource really exists in the resource hierarchy, false otherwise.
Returns the locale used to locate the data for the QResource.
See also setLocale().
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.
See also unregisterResource().
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.
Warning: The data must remain valid throughout the life of any QFile that may reference the resource data.
This function was introduced in Qt 4.3.
See also unregisterResource().
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().
See also fileName() and absoluteFilePath().
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.
See also locale() and setFileName().
Returns the size of the data backing the resource.
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.
See also registerResource().
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.
This function was introduced in Qt 4.3.
See also registerResource().
© 2008-2011 Nokia Corporation and/or its subsidiaries. Nokia, Qt and their respective logos are trademarks of Nokia Corporation in Finland and/or other countries worldwide.
All other trademarks are property of their respective owners. Privacy Policy
Licensees holding valid Qt Commercial licenses may use this document in accordance with the Qt Commercial License Agreement provided with the Software or, alternatively, in accordance with the terms contained in a written agreement between you and Nokia.
Alternatively, this document may be used under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation.