- Game Programming Using Qt Beginner's Guide
- Witold Wysota Lorenz Haas
- 350字
- 2025-04-04 20:19:16
Time for action – the main window of the application
Create a new Qt Designer Form Class application. As a template, choose Main Window. Accept the default values for the rest of the wizard.
Create an action using the action editor and enter the following values in the dialog:

Now, create another action and fill it with the values shown in the following screenshot:

We want our game to look nice, so we will provide icons for the actions and we will embed images for them in our application using the resource system. Create a new file and make it Qt Resource File. Call it resources.qrc
. Click on the Add button and choose Add Prefix. Change the value for the prefix to /
. Then, click on the Add button again and choose Add Files. Find appropriate images for your actions and add them to the resource file. A dialog will appear asking whether you want to copy the files to the project directory. Agree by choosing Copy.

Now, edit the actions again in the Action Editor and choose icons for them.
What just happened?
We added a resource file to our project. In that resource file, we created entries for a number of images. Each of the images is put under a /
prefix, which stands for the root node of the artificial filesystem that we create. Each entry in a resource file can be accessed directly from the manually written code as a file with a special name. This name is assembled from three components. First comes a colon character (:
), which identifies the resource filesystem. This is followed by a prefix (for example, /
) and a full path of the entry in the resource (for example, exit.png
). This makes an image called exit.png
accessible through the :/exit.png
path. When we build the project, the file will be transformed into a C data array code and integrated with the application binary. Having prepared the resource file, we used images embedded there as icons for our actions.
The next step is to add these actions to a menu and toolbar.