Viadeo Twitter Google Bookmarks ! Facebook Digg del.icio.us MySpace Yahoo MyWeb Blinklist Netvouz Reddit Simpy StumbleUpon Bookmarks Windows Live Favorites 
Logo Documentation Qt ·  Page d'accueil  ·  Toutes les classes  ·  Toutes les fonctions  ·  Vues d'ensemble  · 

QResource Class Reference
[QtCore module]

The QResource class provides an interface for reading directly from resources. More...

 #include <QResource>

Note: All the functions in this class are reentrant.

This class was introduced in Qt 4.2.

Public Functions

Static Public Members

Protected Functions


Detailed Description

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 through the 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.

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 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.


Member Function Documentation

QResource::QResource ( const QString & file = QString(), const QLocale & locale = QLocale() )

Constructs a QResource pointing to file. locale is used to load a specific localization of a resource data.

See also QFileInfo, searchPaths(), setFileName(), and setLocale().

QResource::~QResource ()

Releases the resources of the QResource object.

QString QResource::absoluteFilePath () const

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

See also fileName().

QStringList QResource::children () const   [protected]

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

See also isDir().

const uchar * 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 and qUncompress() must be used to access the data. If the resource is a directory 0 is returned.

See also size(), isCompressed(), and isFile().

QString QResource::fileName () const

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

See also setFileName() and absoluteFilePath().

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 also data() and isFile().

bool QResource::isDir () const   [protected]

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

See also isFile().

bool QResource::isFile () const   [protected]

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

See also isDir().

bool QResource::isValid () const

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

QLocale QResource::locale () const

Returns the locale used to locate the data for the QResource.

See also setLocale().

bool QResource::registerResource ( const QString & rccFileName, const QString & mapRoot = QString() )   [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.

See also unregisterResource().

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

This is an overloaded member function, provided for convenience.

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().

QStringList QResource::searchPaths ()   [static]

Returns the current search path list. This list is consulted when creating a relative resource.

See also addSearchPath().

void QResource::setFileName ( const QString & file )

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

See also fileName() and absoluteFilePath().

void QResource::setLocale ( const QLocale & locale )

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().

qint64 QResource::size () const

Returns the size of the data backing the resource.

See also data() and isFile().

bool QResource::unregisterResource ( const QString & rccFileName, const QString & mapRoot = QString() )   [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.

See also registerResource().

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

This is an overloaded member function, provided for convenience.

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().

Publicité

Best Of

Actualités les plus lues

Semaine
Mois
Année
  1. « Quelque chose ne va vraiment pas avec les développeurs "modernes" », un développeur à "l'ancienne" critique la multiplication des bibliothèques 103
  2. Pourquoi les programmeurs sont-ils moins payés que les gestionnaires de programmes ? Manquent-ils de pouvoir de négociation ? 56
  3. «Le projet de loi des droits du développeur» : quelles conditions doivent remplir les entreprises pour que le développeur puisse réussir ? 97
  4. Les développeurs détestent-ils les antivirus ? Un programmeur manifeste sa haine envers ces solutions de sécurité 32
  5. Qt Commercial : Digia organise un webinar gratuit le 27 mars sur la conception d'interfaces utilisateur et d'applications avec le framework 0
  6. Quelles nouveautés de C++11 Visual C++ doit-il rapidement intégrer ? Donnez-nous votre avis 10
  7. 2017 : un quinquennat pour une nouvelle version du C++ ? Possible, selon Herb Sutter 11
Page suivante
  1. Linus Torvalds : le "C++ est un langage horrible", en justifiant le choix du C pour le système de gestion de version Git 100
  2. Comment prendre en compte l'utilisateur dans vos applications ? Pour un développeur, « 90 % des utilisateurs sont des idiots » 231
  3. Quel est LE livre que tout développeur doit lire absolument ? Celui qui vous a le plus marqué et inspiré 96
  4. Apple cède et s'engage à payer des droits à Nokia, le conflit des brevets entre les deux firmes s'achève 158
  5. Nokia porte à nouveau plainte contre Apple pour violation de sept nouveaux brevets 158
  6. « Quelque chose ne va vraiment pas avec les développeurs "modernes" », un développeur à "l'ancienne" critique la multiplication des bibliothèques 103
  7. Quel est le code dont vous êtes le plus fier ? Pourquoi l'avez-vous écrit ? Et pourquoi vous a-t-il donné autant de satisfaction ? 83
Page suivante

Le Qt Labs au hasard

Logo

QLocale : à propos du temps (et des dates, et des langues, et des...)

Les Qt Labs sont les laboratoires des développeurs de Qt, où ils peuvent partager des impressions sur le framework, son utilisation, ce que pourrait être son futur. Lire l'article.

Communauté

Ressources

Liens utiles

Contact

  • Vous souhaitez rejoindre la rédaction ou proposer un tutoriel, une traduction, une question... ? Postez dans le forum Contribuez ou contactez-nous par MP ou par email (voir en bas de page).

Qt dans le magazine

Cette page est une traduction d'une page de la documentation de Qt, écrite par Nokia Corporation and/or its subsidiary(-ies). Les éventuels problèmes résultant d'une mauvaise traduction ne sont pas imputables à Nokia. Qt qtextended4.4
Copyright © 2012 Developpez LLC. Tous droits réservés Developpez LLC. Aucune reproduction, même partielle, ne peut être faite de ce site et de l'ensemble de son contenu : textes, documents et images sans l'autorisation expresse de Developpez LLC. Sinon, vous encourez selon la loi jusqu'à 3 ans de prison et jusqu'à 300 000 E de dommages et intérêts. Cette page est déposée à la SACD.
Vous avez déniché une erreur ? Un bug ? Une redirection cassée ? Ou tout autre problème, quel qu'il soit ? Ou bien vous désirez participer à ce projet de traduction ? N'hésitez pas à nous contacter ou par MP !
 
 
 
 
Partenaires

Hébergement Web