Installing the QT in Raspberry pi is very easy using the command line, but it will take 30 minutes to 4 hours to finish the installation depending upon the speed of the internet connection. Downloading and installing the fourth version, QT4 using commands are already discussed in a previous article.In this project the Raspberrypi board is loaded with Ubuntu and is remotely accessed using VNC.
Once the installation is complete the user can find them listed under the installed programs for ‘Programming’ as shown in the following image:
Fig. 2: QT Listed in Istalled Programs
The list includes “Qt 4 Assistant”, “Qt 4 Designer”, “Qt 4 Linguist” and “Qt Creator”. The “Qt 4 Assistant” is basically provides help in the form of documentations related to the topics in QT. “Qt 4 Designer” is where the user can create a design and save it as a ‘.ui’ file which can then be used in QT projects. The “Qt 4 Linguist” provides a language view of the design created. The “Qt Creator” is where all these things can be done in the same IDE which helps in creating a GUI using QT.
Click on the “Qt Creator” and the following window opens up which includes options for creating a project, editing the code, design the UI and even option for debugging. Options are available in the same window for compile, build and run also.
Fig. 3: Qt Creator Window For Programming In Raspberry Pi
For creating a new application double click on the “Create Project” and the following window appears.
Fig. 4: Create New Aplication With Qt GUI Apllication In New Project Window
Select the “Applications” >> “QtGui Applications” and click on the “Choose” button. The following steps are about the files to be generated and the location where they need to be generated.
Fig. 5: Create Project Introduction And Location In Qt GUI Apllication Window Of Raspberry Pi
This window asks the location where the project files need to be saved. It is suggested to create a separate folder for each and every QT project since they will generate many numbers of files for a single project. Here a folder named “hello_world” has been created for the project at /home/pi/raspberry_piQT/hello_world and the name of the project is also given as ‘hello_world’.
Click on the “Next” button and the following window appears:
Fig. 6: Target Setup In QT Creator Window For Programing In Raspberry Pi
Check the “Embedded Linux” and then click the “Next” button. The next window will list the source code files that will be available for programming.
Fig. 7: Source Code Files Options For Programming In QT
Click the “Next” button and the following window displays a list of the files that are generated for the project.
Fig. 8: List Of The Files Generated For The Project In Raspberry Pi
As soon as the “Finish” button is clicked the “Edit” window of the Qt Creator will open up as shown in the following image:
Fig. 9: Edit Window In Qt Creator For Programming
Expand the “Forms” where the “mainwindow.ui” can be seen listed.
Fig. 10: “mainwindow.ui” Listed In Forms Of QT Creator
Now double click on the “mainwindow.ui” and the Qt Creator’s “Design” window opens up:
Fig. 11: Qt Creator’s “Design” Window On Raspberry Pi
This is where the user can enjoy designing the GUI with the help of Drag & Drop components on the left hand side of the window.
For this simple project a simplest text displaying component called “Label” can be dragged out of the “Display Widgets” to the main dialogue box as shown in the following image:
Fig. 12: Drag Text Lable From ” Display Widgets” to type Hello World
Right click on the “Label” and change the default text to “HELLO WORLD” using the “Change Plain Text” option.
Fig. 13: Changing Default Text To “HELLO WORLD” QT Creator Window
This simple project finishes the design part with that and moving on to the compiling and running parts which are discussed in the following;
There is a button at the bottom left corner of the window as marked in the following image, which can be used to build the project.
Fig. 14: Build Project With Button In QT Creator Tool Bar
Use the “Compile Output” tab to read the compilers output while compiling the code. Once the compilation is finished successfully the last line reads as “The process /usr/sbin/make exited normally”, otherwise the errors will be displayed along with the line where the error occurred.
Fig. 15: Compilation Successful Message
To execute the application one method is to use the command line and change the directory to where the project is saved. Another folder can be seen inside that named “hello_world-build-embedded-Qt_4_8_2_in_PATH__System__Release”. List the files in the directory using the following command:
Fig. 16: Command To List Files In Directory In QT
The green colored file is the executable file here and which can be executed using the following command:
The simple window with a text “HELLO WORLD” appears shown in the following image:
Fig. 17: “Hello World” Program On Screen Using QT In Raspberry Pi