Go back to Richel Bilderbeek's homepage.
Go back to Richel Bilderbeek's C++ page.




This Qt example shows how to using resources, like this screenshot (png).
Using resources in Qt Creator 2.0.0
Here follows a step-by-step guide to add a bitmap as a resource to a Qt Creator project:
- View screenshot
- In the Project Manager, right-click on the project name on on the 'Sources' folder. Click 'Add New'
- View screenshot
- In the 'New File' dialog, select to create a new 'Qt Resource file'
- View screenshot
- In the 'New Qt Resource file -> Location' dialog, give the resource file a name. For example, 'MyResources'
- View screenshot
- In the 'New Qt Resource file -> Project management' dialog, click 'Finish'
- View screenshot
- As you can see, 'MyResources.qrc' has now been added to the Project Manager. Double-click on 'MyResources.qrt' and click 'Add -> Add Prefix' (which is all there is to choose yet)
- View screenshot
- Change the prefix to a more fitting name, for example 'MyImages'.
- View screenshot
- Click 'Add -> Add Files' and add an image. In this example, this is a file called 'BeerSmall.bmp' (a sprite from BeerWanter)
- View screenshot
- Now, the file has been added to your resources. The image can be accessed with the filename ':/MyImages/BeerSmall.bmp'
- View screenshot
- Copy-paste the example code below
- View final screenshot
Technical facts
Application type(s)
Operating system(s) or programming environment(s)
IDE(s):
Project type:
C++ standard:
Compiler(s):
Libraries used:
Qt: version 5.4.1 (32 bit)
STL: GNU ISO C++ Library, version 4.9.2
Qt project file: ./CppQtExample16/CppQtExample16.pro
./CppQtExample16/main.cpp
Go back to Richel Bilderbeek's C++ page.
Go back to Richel Bilderbeek's homepage.

This page has been created by the tool CodeToHtml