Creating Qt Applications on a Raspberry Pi

(as of 01-April-2017)

Make the VNC Server run automatically at startup:

cd /home/pi/.config

mkdir autostart

cd autostart

sudo leafpad tightvnc.desktop   This creates the file to run the necessary commands

Enter the following in the text editor and save:

[Desktop Entry]

Type=Application

Name=TightVNC

Exec=vncserver-x11-serviced enable

StartupNotify=false      

 

Install the GNU Compiler Collection (GCC):

sudo apt-get install gcc

Install X-Term:

sudo apt-get install xterm

Install Qt:

sudo apt-get install qt4-dev-tools libqt4-dev libqt4-core libqt4-gui

Install QtCreator:

sudo apt-get install Qtcreator

Install other things that seem to help:

sudo apt-get install cmake kdelibs5-data subversion

sudo apt-get install ninja-build

sudo apt-get install build-essential

Run Qt Creator (should now be under Programming in the Raspberry menu)

Click on Help, About Plugins:

Scroll to Device Support. Since we want to build applications to build and run locally on the Pi, uncheck RemoteLinux and Android.  Check BareMetal, then Close:

Select Tools, Options.  In the left pane, select Build & Run.

Click on the Compilers tab.  Click the Add button, and select GCC from the dropdown list.

Several options will appear.  Click the Browse… button on the Compiler path: option, navigate to /usr/bin, and select the file gcc.  Click the Apply button

Select the Qt Versions tab.  It should appear similar to this:

Click on the Kits tab.  NOTE: the default Desktop kit will not work!  Click Add to create a new kit manually.  Give it a name, and select GCC for the compiler.  If you’re lucky, everything else will default to the correct values:

Click OK.  You should be ready to make your first Qt application and run it on the Pi:

Click on the New Project button. Select Qt Widgets Application and click Choose…

Give your project a Name: and click Next >

You should now be able to select the kit you just created:

Make sure MyKit is checked, and click Next > .  The Class Information form will appear.  For now, leave it as-is, and click Next > .  The Project Management form will appear, showing what is about to be created.  Leave as-is, and click Finish.

Click on the green “Play” () button.  Qt Creator will compile the application and run it:

See that blank MainWindow window?  Congratulations, you’ve made a Qt application.  Amuse yourself by dragging it around the screen, when you are bored, click the ‘x’ to close the application and return to Qt Creator.