The next item for the GUI is to add items to the tool bar, which has already been created, but is currently only blank. Unlike the menu items which are text, the tool bar items are icons. It is convenient if the icons are part of the application file and not separate files that must be included to run and must be loaded by the application.
This is accomplished by converting the icon files into C++ source files that are then compiled and linked into the application. The Qt Resource Compiler (RCC) is used to convert the icon files to source files. All the resources for the program are listed in an XML resource (
.qrc) file.
QtCreator makes it easy to create and maintain these resource files.
To create the resource file, the new file wizard was again utilized. Under
Files and Classes the
Qt item (lower-left) and
Qt Resource file (upper-right) was selected. On the next
Choose the Location dialog, the
Name: field was set to
ibcp.qrc. On the next
Project Management dialog, the defaults were selected (which was set to
git). Once finished,
QtCreator opened up a specific resources editing window.
To start simple, an application icon was given to the program, which will appear in the upper corner of the application window and on the task bar of the OS. Up to now, a generic icon was being used (an X icon on Linux/KDE and a generic program icon on Windows). An icon file was created by the name
ibcp.png and placed in the new
images sub-directory. The image chosen and created consists of two lightning bolts, which represents the letter I, two to represent
Interactive and
Incremental, for the type of BASIC compiler being created. The lightning bolt itself represents speed, since the goal of this project is to make a
fast interactive BASIC compiler.
To add this new icon to the resource file, the
Add button at the bottom resource editing window was clicked and
Add Prefix was selected. The
Prefix: field, which defaulted to
/new/prefix1 was cleared (which set it to a single slash). The
Add/
Add Files was then selected, which opened a file selection dialog. The
images/ibcp.png file was selected, which added the file to the resource list.
To assign this icon file to the application, in
Designer, the
MainWindow object was selected (upper-right panel) and under properties (lower-right panel), the
... button was clicked for the
windowIcon property, which displayed a
Select Resource dialog. The
images item (left-side) was selected, which displayed the
ibcp.png icon (right-side), which was selected.
To finish, the building of the resources needed to be added to the CMake build file. Resources are handled by the
qt4_add_resources command that is added as part of the Qt4 CMake module. This command is given a list of resource files (in this case
ibcp.qrc) and produces a list of resource source files that are generated by RCC. This list of generated source files was then added to the
add_executable command.
[commit ba9ee1be2a]