[Previous: Adding Form Files to the Project] [Contents] [Next: Creating Custom Widget Plugins for the Integration]
Adding new resources to a Qt project works similar to adding resources to a normal C++ project, the main difference being that .qrc files (Qt resource files) are used instead of Windows .rc files. Unlike .rc files, .qrc files work on all platforms supported by Qt and are trivial to load from Qt code.

To add new resources, you must first create a new .qrc file. To do this, open the Add New Item dialog, select Qt Resource File from the Qt Project Items folder, and click Open. The newly created .qrc file will be displayed inside Visual Studio.
At this point, the .qrc file only contains a prefix called like the project. You can add resources under that prefix by selecting it and clicking on the Add button on the right hand side. Then click Add File in the context menu. Now Visual Studio will display a dialog that allows you to add an existing file or create new resources. To add an existing file, click Import and choose a file using the file dialog. To create a new resource, choose a file type and enter a file name, then click New.
When referring to the resources later on from Qt code, you must prepend the prefix, the file name, and a colon. For example, :/MyProject/print.bmp. Using the context menu, you can rename the predefined prefix or add other prefixes to the .qrc file.
See Qt Resource System for more information.
If the desired file type is not listed in the Resource Dialog, you can add it by providing three files to Visual Studio: a file describing the new resource type, a template file of that type, and an optional icon. The description file is an XML file containing information about the new type.
For example, the following file describes the PostScript resource type:
<code>
<QtResourceType Name="PostScript File">
<TemplateFile>empty.ps</TemplateFile>
<Icon>postScriptIcon.bmp</Icon>
</QtResourceType>
</code>
The Name attribute of the QtResourceType tag defines a user-readable name for the resource type (e.g., "PostScript File"). The TemplateFile tag specifies the name of a file that contains the default data for this type (e.g., an empty PostScript document). Lastly, the Icon tag specifies an image file that represents the data file type.
These three files must be located in the resources directory in the install path of the integration.
[Previous: Adding Form Files to the Project] [Contents] [Next: Creating Custom Widget Plugins for the Integration]
| Copyright © 2008 Trolltech | Trademarks | Qt 1.4 |