philm001
Posts: 7
Joined: Sat Apr 27, 2019 8:51 pm

Creating a Raspberry Pi program in Qt Creator

Sat Apr 27, 2019 9:13 pm

Hello all,

I am new to Raspberry Pi. I have experience using Linux (specifically Ubuntu), C/C++, and Qt. However, I am looking to work on a project where I need to create a GUI program that runs on the Raspberry pi 3. The program will also need to interface to some of the GPIO pins and peripherals and interface to a touch screen device.

I do have some questions regarding developing on the Raspberry Pi 3 that I am hoping the community can answer

1) Looking at a number of tutorials, it seems that it is best to build my application on a Desktop computer and then cross-compile the application for Raspberry Pi. I could develop on the Pi itself but compiling time would be longer and I am limited to Qt4.

1a)That last statement was from websites dated 2+ years ago. In 2019, does this still apply?

1b) Is it still best to develop on a desktop and then export the project as a cross compiled application? Or does Qt5 exist for the Pi?

I will be referencing these tutorials when building my application on the Desktop:

https://medium.com/@amirmann/how-to-cro ... 5acf2a078c
https://wiki.qt.io/Native_Build_of_Qt_5 ... spberry_Pi
https://wiki.qt.io/Raspberry_Pi_Beginners_Guide

1c) Again, some of these tutorials are more then 2 years old. Do they apply today or are updated tutorials available?

2) How can I program the GPIO pins and peripherals of the PI 3 in Qt creator? I come from the microcontroller land and usually, I would reference the registers directly. I have minor experience working with SOM chips.

2a) With the Pi 3 running Linux, would I be programming with the Linux Kernel itself instead of working directly with the registers?

2b)If I do need to work with the registers directly, I can I reference them in my source code?

3) Bonus Question: I would like my application to be the only application running on the Pi 3. Are there any ways that I can bypass the OS (or a portion of the OS) such that as soon as the Pi 3 boots up, the Qt application runs? I do not want the user of my application need to login into the OS before my app starts.

Thank you all and I look forward to reviewing your feedback.

User avatar
procount
Posts: 1782
Joined: Thu Jun 27, 2013 12:32 pm
Location: UK

Re: Creating a Raspberry Pi program in Qt Creator

Sat Apr 27, 2019 11:57 pm

Why don't you have at look at the source code for NOOBS. https://github.com/raspberrypi/noobs
It is built using QT4.8
It runs a small version of Linux built using buildroot, but it boots straight into the noobs recovery program, bypassing a lot of the usual linux startup stuff, so some you have to start up yourself.
It uses some GPIO and interfaces to the RPF touchscreen. I also got it to work with the Pimoroni Hyperpixel 3.5 and 4.0" touchscreen displays.

It is best built on a PC (e.g. Ubuntu Linux x86 or Debian with Raspbian Desktop for x86) but you can also build it on a RPi itself, it just takes a lot longer. The initial build of the kernel and particularly the QT libraries takes a very long time on the Pi, bit once you've done it once, subsequent rebuilds of just your App are quite acceptable on a Pi 3.
PINN - NOOBS with the extras... https://www.raspberrypi.org/forums/viewtopic.php?f=63&t=142574

philm001
Posts: 7
Joined: Sat Apr 27, 2019 8:51 pm

Re: Creating a Raspberry Pi program in Qt Creator

Sun Apr 28, 2019 8:17 pm

Hello procount,

Thank you for the info. It looks like what you are suggesting will help with the Bonus Question.

I have started going through the documentation. It looks like it is meant to install other OS onto the Pie 3. I am not sure how it will assist in only having my Qt application running after bootup.

User avatar
procount
Posts: 1782
Joined: Thu Jun 27, 2013 12:32 pm
Location: UK

Re: Creating a Raspberry Pi program in Qt Creator

Sun Apr 28, 2019 8:48 pm

Obviously the purpose of noobs is totally different to your application. It was meant only as an example of how to create a framework that satisfies your requirements and even has an example of reading gpio.
You would have to adapt it or even replace the recovery program entirely to match your application. The recovery program itself is an example of a orogram that runs directly after boot
PINN - NOOBS with the extras... https://www.raspberrypi.org/forums/viewtopic.php?f=63&t=142574

Heater
Posts: 13685
Joined: Tue Jul 17, 2012 3:02 pm

Re: Creating a Raspberry Pi program in Qt Creator

Mon Apr 29, 2019 4:50 am

philm001,

My approach to creating Qt application for the Pi has been as follows:

1) Write the application on a PC using qtcreator. I use Linux but I'm sure it goes the same on Windows and Mac.

2) Of course one can build, run, test your application on the PC as usual.

3) When the application is in good shape, or a good chunk of it, move the source code to a Pi and rebuild it there using qmake and make

4) Do some testing on the Pi. Make small fixes there if need be. I don't bother using qtcreator on the Pi, any editor will do, and qmake/make.

5) For further development, go back to the PC and work on it in the luxury of its performance and facilities. Step 1) above.

Of course one cannot use Pi GPIO and other Pi specific features whilst developing on the PC. That's OK just create some stub classes/functions to fill in for those. Better still use those stubs to simulate the GPIO and such, this makes a lot of testing possible on the PC itself and one can make repeatable tests, which is a good thing.

To move code from PC to Pi and back again I use git. Push the code to a git repository from the PC, clone/pull it to the Pi. And vice versa. I use github and bitbucket but one can use ones own local git repository on any machine.

Working this way saves all the hassle of having to use cross-compilers on the PC and then moving binary executables around.

Oh, actually, if you use the pigpio daemon on the Pi you can have your Qt application talk to GPIO and such though it whilst running on the PC. http://abyz.me.uk/rpi/pigpio/pigpiod.html

Otherwise I have written my own Qt code to access GPIO directly using these examples as a basis: https://elinux.org/RPi_GPIO_Code_Samples
Memory in C++ is a leaky abstraction .

philm001
Posts: 7
Joined: Sat Apr 27, 2019 8:51 pm

Re: Creating a Raspberry Pi program in Qt Creator

Mon Apr 29, 2019 6:42 pm

Hello Heater,

Thank you for your reply. Does the Pi 3 support Qt5.0 now? Because my understanding is that Pi 3 supports up to Qt 4.8?

fruitoftheloom
Posts: 20930
Joined: Tue Mar 25, 2014 12:40 pm
Location: Delightful Dorset

Re: Creating a Raspberry Pi program in Qt Creator

Mon Apr 29, 2019 7:50 pm

philm001 wrote:
Mon Apr 29, 2019 6:42 pm
Hello Heater,

Thank you for your reply. Does the Pi 3 support Qt5.0 now? Because my understanding is that Pi 3 supports up to Qt 4.8?

Pedantic but it is the operating system which denotes which software is available:

Raspbian Stretch has QT5.7 packages.

https://packages.debian.org/source/stre ... source-src
Retired disgracefully.....

mfaghani
Posts: 3
Joined: Sat Feb 16, 2019 1:04 pm

Re: Creating a Raspberry Pi program in Qt Creator

Mon Apr 29, 2019 7:59 pm

I'm using Qt5 with Raspberry Pi 3A+, Raspbian (Stretch):

Code: Select all

sudo apt update
sudo apt install qt5-default

And also if you're using Serial Port:

Code: Select all

apt-get update libqtserialport5-dev

I'd had errors with Multimedia before these:

Code: Select all

apt-get update qtmultimedia5-dev
apt-get install libqt5multimedia5-plugins

philm001
Posts: 7
Joined: Sat Apr 27, 2019 8:51 pm

Re: Creating a Raspberry Pi program in Qt Creator

Tue Apr 30, 2019 12:12 am

fruitoftheloom wrote:
Mon Apr 29, 2019 7:50 pm
philm001 wrote:
Mon Apr 29, 2019 6:42 pm
Hello Heater,

Thank you for your reply. Does the Pi 3 support Qt5.0 now? Because my understanding is that Pi 3 supports up to Qt 4.8?

Pedantic but it is the operating system which denotes which software is available:

Raspbian Stretch has QT5.7 packages.

https://packages.debian.org/source/stre ... source-src
Wow, that is very good to know. Looks like many of the tutorials that I found are out of date!

Anyways, I like the Wiring Pi for interfacing with the GPIO. The format looks exactly the same with Arduino!

Heater
Posts: 13685
Joined: Tue Jul 17, 2012 3:02 pm

Re: Creating a Raspberry Pi program in Qt Creator

Tue Apr 30, 2019 4:02 am

philm001,
Looks like many of the tutorials that I found are out of date!
Yes. Rule 1 of searching for any programming/technical information on the net is to always assume that whatever you find is wrong. To be treated as a hint, a suggestion. One always has to double check.

So often we find program examples, installation / configuration instructions etc do not work for us. For many reasons:

1) The software they used has been updated and we have newer.

2) The operating system they use has been updated.

3) The operating system they used is different from ours.

4) Some other library or program their example depends on has been updated or is different from what we have.

5) Some communications protocol they use has changed since the article was written.

6) The solution in the article we find is just wrong anyway.

I wish people writing such blogs, tutorials, random examples would put a date of publication on everything, together with operating system and version, version numbers of all software component used. Then we would have more chance of knowing what is current and what is likely to work. Or at least be aware of potential problems.
I like the Wiring Pi for interfacing with the GPIO. The format looks exactly the same with Arduino!
That might be why it's called Wiring Pi.
Memory in C++ is a leaky abstraction .

philm001
Posts: 7
Joined: Sat Apr 27, 2019 8:51 pm

Re: Creating a Raspberry Pi program in Qt Creator

Fri May 03, 2019 2:55 pm

mfaghani wrote:
Mon Apr 29, 2019 7:59 pm
I'm using Qt5 with Raspberry Pi 3A+, Raspbian (Stretch):

Code: Select all

sudo apt update
sudo apt install qt5-default

And also if you're using Serial Port:

Code: Select all

apt-get update libqtserialport5-dev

I'd had errors with Multimedia before these:

Code: Select all

apt-get update qtmultimedia5-dev
apt-get install libqt5multimedia5-plugins
Real quick, would you (or someone) be able to confirm if these commands also install the Qt IDE?

User avatar
procount
Posts: 1782
Joined: Thu Jun 27, 2013 12:32 pm
Location: UK

Re: Creating a Raspberry Pi program in Qt Creator

Fri May 03, 2019 3:20 pm

Sudo apt-get install qtcreator
PINN - NOOBS with the extras... https://www.raspberrypi.org/forums/viewtopic.php?f=63&t=142574

dsyleixa123
Posts: 424
Joined: Mon Jun 11, 2018 11:22 am

Re: Creating a Raspberry Pi program in Qt Creator

Fri May 03, 2019 4:59 pm

Heater wrote:
Tue Apr 30, 2019 4:02 am
I like the Wiring Pi for interfacing with the GPIO. The format looks exactly the same with Arduino!
That might be why it's called Wiring Pi.
that is actually not true:
WiringPi is programmed in C, Arduino in C++.
Some commands are sort of similar, but many are not at all and have a totally different syntax, which is very confusing , tbh!
(e.g.: Serial() class, Wire() class, analogWrite for pwm,...)

Heater
Posts: 13685
Joined: Tue Jul 17, 2012 3:02 pm

Re: Creating a Raspberry Pi program in Qt Creator

Fri May 03, 2019 5:12 pm

It's sort of true. "Wiring", "Processing", "Arduino", "Wiring Pi" are all related by inspiring each other some how, despite using different languages, Java, C++, C.

See here: https://en.wikipedia.org/wiki/Wiring_(d ... _platform)
Memory in C++ is a leaky abstraction .

dsyleixa123
Posts: 424
Joined: Mon Jun 11, 2018 11:22 am

Re: Creating a Raspberry Pi program in Qt Creator

Fri May 03, 2019 5:25 pm

Heater wrote:
Fri May 03, 2019 5:12 pm
It's sort of true. "Wiring", "Processing", "Arduino", "Wiring Pi" are all related by inspiring each other some how, despite using different languages, Java, C++, C.

See here: https://en.wikipedia.org/wiki/Wiring_(d ... _platform)
I have to disagree.
The Wiring concept by Hernando Barragán (see https://arduinohistory.github.io/) uses C++, is based on Processing, and Java (and go) are "processing" the simplified Arduino API C++ Sketch code to an intermediate C++ code for compile, makefile, link, and upload.

JFYI, compare the Arduino Syntax for
Serial (UART)
https://www.arduino.cc/reference/en/lan ... on/serial/
if(Serial)
available()
availableForWrite()
begin()
end()
find()
findUntil()
flush()
parseFloat()
parseInt()
peek()
print()
println()
read()
readBytes()
readBytesUntil()
readString()
readStringUntil()
setTimeout()
write()
serialEvent()


Wire (i2c)
https://www.arduino.cc/en/Reference/Wire
begin()
requestFrom()
beginTransmission()
endTransmission()
write()
available()
read()
SetClock()
onReceive()
onRequest()


and analogWrite for pwm,
https://www.arduino.cc/reference/en/lan ... alogwrite/

and then see when "wiringPi" does apply to that or not.

swampdog
Posts: 246
Joined: Fri Dec 04, 2015 11:22 am

Re: Creating a Raspberry Pi program in Qt Creator

Sat May 04, 2019 9:01 am

Has someone got 2G of public space?

I have a debug build of QT 5.12.1. QtCreator 4.8.1.

philm001
Posts: 7
Joined: Sat Apr 27, 2019 8:51 pm

Re: Creating a Raspberry Pi program in Qt Creator

Wed May 08, 2019 6:01 pm

Heater wrote:
Mon Apr 29, 2019 4:50 am

Oh, actually, if you use the pigpio daemon on the Pi you can have your Qt application talk to GPIO and such though it whilst running on the PC. http://abyz.me.uk/rpi/pigpio/pigpiod.html
Can you explain this part a little bit more? It almost sounds like the library will communicate with the PI (while running on a PC) to command the GPIO states

dsyleixa123
Posts: 424
Joined: Mon Jun 11, 2018 11:22 am

Re: Creating a Raspberry Pi program in Qt Creator

Wed May 08, 2019 7:36 pm

I'm curious if you managed to install qt5 and qtcreator -
I once tried but failed completely...:

sudo apt-get install qt5-default // edited: c+p typo
sudo apt-get install qtcreator

After choosing
file...new..Projects...Qt-Widgets-Project (acually shown installed German option names)
and after entering the name for my new project I get the error message
"Es wurden keine gültigen Kits gefunden!" (no valid kits found)
viewtopic.php?f=33&t=232813

no advices here in this forum where to get those obscured tools and how to integrate them so I abandoned that mess.

Did YOU make it work?
Last edited by dsyleixa123 on Fri May 10, 2019 5:19 pm, edited 1 time in total.

Heater
Posts: 13685
Joined: Tue Jul 17, 2012 3:02 pm

Re: Creating a Raspberry Pi program in Qt Creator

Thu May 09, 2019 4:35 am

Yes.

"kits" in qtcreator are just configurations telling what compiler and other build tools it should use. And how your project is to be built. You can set up different "kits" that use different compiler versions, different compilers, cross-compiles etc.

A quick google search will find you hundreds of links to documentation, instructions, videos about how to set up qtcreator kits.

It's all very flexible and useful but comes at the cost of that little complexity to get it set up initially.
Memory in C++ is a leaky abstraction .

dsyleixa123
Posts: 424
Joined: Mon Jun 11, 2018 11:22 am

Re: Creating a Raspberry Pi program in Qt Creator

Thu May 09, 2019 8:16 am

I tried all I could find but all in vain
tbh, 1st of all: I didn't ask you but the OP,
and 2nd, posts like yours which say "try to google" are actually rediculous.

philm001
Posts: 7
Joined: Sat Apr 27, 2019 8:51 pm

Re: Creating a Raspberry Pi program in Qt Creator

Thu May 09, 2019 3:33 pm

dsyleixa123 wrote:
Thu May 09, 2019 8:16 am
I tried all I could find but all in vain
tbh, 1st of all: I didn't ask you but the OP,
and 2nd, posts like yours which say "try to google" are actually rediculous.
Hello, sorry, I haven't tried that. I am still working out some of the details for the project. Just doing some information gathering

Heater
Posts: 13685
Joined: Tue Jul 17, 2012 3:02 pm

Re: Creating a Raspberry Pi program in Qt Creator

Thu May 09, 2019 7:34 pm

dsyleixa123,
I tried all I could find but all in vain
tbh, 1st of all: I didn't ask you but the OP,
You did not specify that.

In general I think it's assumed that a question asked on a public forum is an invitation to anyone willing to help.
...posts like yours which say "try to google" are actually rediculous.
Often I would agree with you.

In this case I felt that trying to give directions here would only be a repetition of what is found in seconds on all over the net already.

I'll make a note not to bother you with any help in future.
Memory in C++ is a leaky abstraction .

dsyleixa123
Posts: 424
Joined: Mon Jun 11, 2018 11:22 am

Re: Creating a Raspberry Pi program in Qt Creator

Fri May 10, 2019 5:17 pm

Heater wrote:
Thu May 09, 2019 7:34 pm
In this case I felt that trying to give directions here would only be a repetition of what is found in seconds on all over the net already
either show me the detailed install steps and the single settings for "tools" or move on.
in case not,
I'll make a note not to bother you with any help in future.
then I'll appreciate that very much, hollow chatter wouldn't help anyway.

Heater
Posts: 13685
Joined: Tue Jul 17, 2012 3:02 pm

Re: Creating a Raspberry Pi program in Qt Creator

Fri May 10, 2019 6:19 pm

dsyleixa123,
either show me the detailed install steps and the single settings for "tools" or move on.
Often when people have a problem, if I have a free moment and I'm curious about the question myself, I do indeed do peoples google searching for them, check what I find works and post a working result.

However, uncouth and rude feedback makes that impossible in your case. Good luck.
Memory in C++ is a leaky abstraction .

dsyleixa123
Posts: 424
Joined: Mon Jun 11, 2018 11:22 am

Re: Creating a Raspberry Pi program in Qt Creator

Sat May 11, 2019 6:02 am

Heater wrote:
Fri May 10, 2019 6:19 pm
However, uncouth and rude feedback makes that impossible in your case. Good luck.
what do you expect in reply to hollow and snooty statements like
A quick google search will find you hundreds of links
:?

Return to “C/C++”