Movatterモバイル変換


[0]ホーム

URL:


We bake cookies in your browser for a better experience. Using this site means that you consent.Read More

Menu

Qt Documentation

QResource Class

TheQResource class provides an interface for reading directly from resources.More...

Header:#include <QResource>
Since: Qt 4.2

Note: All functions in this class arereentrant.

Public Functions

QResource(const QString & file = QString(), const QLocale & locale = QLocale())
~QResource()
QStringabsoluteFilePath() const
const uchar *data() const
QStringfileName() const
boolisCompressed() const
boolisValid() const
QLocalelocale() const
voidsetFileName(const QString & file)
voidsetLocale(const QLocale & locale)
qint64size() const

Static Public Members

boolregisterResource(const QString & rccFileName, const QString & mapRoot = QString())
boolregisterResource(const uchar * rccData, const QString & mapRoot = QString())
boolunregisterResource(const QString & rccFileName, const QString & mapRoot = QString())
boolunregisterResource(const uchar * rccData, const QString & mapRoot = QString())

Protected Functions

QStringListchildren() const
boolisDir() const
boolisFile() const

Detailed Description

TheQResource 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 withQFile. The data and children behind aQResource 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.

AQResource 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 byQDir::searchPaths().

AQResource that is representing a file will have data backing it, this data can possibly be compressed, in which caseqUncompress() must be used to access the real data; this happens implicitly when accessed through aQFile. AQResource that is representing a directory will have only children and no data.

Dynamic Resource Loading

A resource can be left out of an application's binary and loaded when it is needed at run-time by using theregisterResource() function. The resource file passed intoregisterResource() must be a binary resource as created by rcc. Further information about binary resources can be found inThe 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 insetFileName().

TheunregisterResource() 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 furtherQResource can be created pointing into this resource data. The resource itself will be unmapped from memory when the lastQResource that points to it is destroyed.

See alsoThe Qt Resource System,QFile,QDir, andQFileInfo.

Member Function Documentation

QResource::QResource(constQString & file = QString(), constQLocale & locale = QLocale())

Constructs aQResource pointing tofile.locale is used to load a specific localization of a resource data.

See alsoQFileInfo,QDir::searchPaths(),setFileName(), andsetLocale().

QResource::~QResource()

Releases the resources of theQResource object.

QString QResource::absoluteFilePath() const

Returns the real path that thisQResource represents, if the resource was found via theQDir::searchPaths() it will be indicated in the path.

See alsofileName().

[protected]QStringList QResource::children() const

Returns a list of all resources in this directory, if the resource represents a file the list will be empty.

See alsoisDir().

constuchar * QResource::data() const

Returns direct access to a read only segment of data that this resource represents. If the resource is compressed the data returns is compressed andqUncompress() must be used to access the data. If the resource is a directory 0 is returned.

See alsosize(),isCompressed(), andisFile().

QString QResource::fileName() const

Returns the full path to the file that thisQResource represents as it was passed.

See alsosetFileName() andabsoluteFilePath().

bool QResource::isCompressed() const

Returns true if the resource represents a file and the data backing it is in a compressed format, false otherwise.

See alsodata() andisFile().

[protected]bool QResource::isDir() const

Returns true if the resource represents a directory and thus may havechildren() in it, false if it represents a file.

See alsoisFile().

[protected]bool QResource::isFile() const

Returns true if the resource represents a file and thus has data backing it, false if it represents a directory.

See alsoisDir().

bool QResource::isValid() const

Returns true if the resource really exists in the resource hierarchy, false otherwise.

QLocale QResource::locale() const

Returns the locale used to locate the data for theQResource.

See alsosetLocale().

[static]bool QResource::registerResource(constQString & rccFileName, constQString & mapRoot = QString())

Registers the resource with the givenrccFileName at the location in the resource tree specified bymapRoot, and returns true if the file is successfully opened; otherwise returns false.

See alsounregisterResource().

[static]bool QResource::registerResource(constuchar * rccData, constQString & mapRoot = QString())

Registers the resource with the givenrccData at the location in the resource tree specified bymapRoot, and returns true if the file is successfully opened; otherwise returns false.

Warning: The data must remain valid throughout the life of anyQFile that may reference the resource data.

This function was introduced in Qt 4.3.

See alsounregisterResource().

void QResource::setFileName(constQString & file)

Sets aQResource to point tofile.file can either be absolute, in which case it is opened directly, if relative then the file will be tried to be found inQDir::searchPaths().

See alsofileName() andabsoluteFilePath().

void QResource::setLocale(constQLocale & locale)

Sets aQResource to only load the localization of resource to forlocale. If a resource for the specific locale is not found then the C locale is used.

See alsolocale() andsetFileName().

qint64 QResource::size() const

Returns the size of the data backing the resource.

See alsodata() andisFile().

[static]bool QResource::unregisterResource(constQString & rccFileName, constQString & mapRoot = QString())

Unregisters the resource with the givenrccFileName at the location in the resource tree specified bymapRoot, and returns true if the resource is successfully unloaded and no references exist for the resource; otherwise returns false.

See alsoregisterResource().

[static]bool QResource::unregisterResource(constuchar * rccData, constQString & mapRoot = QString())

Unregisters the resource with the givenrccData at the location in the resource tree specified bymapRoot, 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 alsoregisterResource().

© 2016 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of theGNU 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.


[8]ページ先頭

©2009-2025 Movatter.jp