| Home |
[Previous: Adding Form Files to the Project] [Contents] [Next: Creating Qt Translation Files for the Project]
Adding new resources to a Qt project works basically the same way as 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 easy to load from Qt code.
To add news resources, you must first create a new .qrc file. To do this, open the Add New Item dialog, select the Qt Resource File item from the Qt Project Items folder, and click Open. The newly created .qrc file will be displayed inside Visual Studio.
At that point, the .qrc file only contains a prefix called /new/prefix1. You can add resources under that prefix by clicking Add File in the context menu. When referring to the resources later on from Qt code, you must prepend the prefix the file name and prepend a colon (e.g., :/new/prefix1/print.bmp). Using the context menu, you can rename the predefined prefix or add other prefixes to the .qrc file.
When you add a new resource using Add File, Visual Studio pops up 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.
See Qt Resource System for more information.
If the desired file type is not listed in the Resource Dialog, it can be added by providing three files to Visual Studio: a file describing the new resource type, a template file of that type, and (optionally) an icon. The description file is an XML file that contains 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). The Icon tag specifies an image file that represents the data file type.
The 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 Qt Translation Files for the Project]
| Copyright © 2007 Trolltech | Trademarks | Qt |