Managing Resources
Adding new resources to a Qt project is similar to adding resources to a normal C++ project. The main difference is 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.
By default, Qt Resource Editor opens in Visual Studio. To run it in a separate window, select Detach.
To run Qt Resource Editor in a separate window by default, select Extensions > Qt VS Tools > Options > Qt Resource Editor, and set Run in detached window to True.
To add new resources:
- Select Project > Add New Item > Installed > Visual C++ > Qt > Qt Resource File.
- In the Name field, enter a name for the resource file.
- In the Location field, specify a location for the file.
- Select Add to create a
.qrc
file and to open it in the Qt Resource Editor. - To add resources to the file, select Add > Add Files.
- In the Prefix field, you can change the prefix.
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
.
To add prefixes to the .qrc
file, select Add > Add Prefix in the Qt Resource Editor.
For more information, see The Qt Resource System.
© 2022 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 the GNU 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.