Graphical library for Raspberry in C / C ++ - Page 1
Forum section: electronics / general

author: luiHS
author_rank: Frequent Contributor
timestamp: September 08, 2021, 03:56:20 am
content: HiI need to develop an application in C / C ++ with a graphical environment for Raspberry, something similar to a video game (although it is not a video game). I have to handle videos with audio, images, texts with artistic fonts, etc.I used QT / QTCreator years ago, but I think it is currently a commercial product, with some very limited free version, so then I prefer not to use it. Searching for Google, I findSFML,GTK+andWxWidgets, I think that all three could be installed and used on CodeBlocks.And for now I haven't found anything else that can be used with C / C ++.Any suggestions or advice on free environments for graphical development with Raspberry, using C or C ++?Regards

author: Nominal Animal
author_rank: Super Contributor
timestamp: September 08, 2021, 05:34:26 pm
content: Qt is dual-licensed. Just choosecommunity editionat the site, so you get the LGPL/GPL-licensed stuff. Or use the distribution-provided development packages. AFAIK, all of the commonly used Qt5 modules are dual-licensed, including Qt Creator, network (built-in browser support) and multimedia; see e.g.here.Qt5 is object-oriented, so you'll want to use either C++ or something like Python3 for the UI.GTK+ is LGPL-licensed, and written in C.Both Qt and GTK+ are extensively used in Linux distributions: Qt in KDE, and GTK+ for most other desktop environments. Some, like XFCE and LXDE, incorporate support for both.There is alsoQt Embedded, so you can run Qt applications under EGL (using the OpenGL drivers provided for Raspberry Pi) without X11, as a full-screen application without any desktop environment at all. However, I do believe you'd need to compile the support libraries yourself from the (GPL/LGPL) sources: not that big of a deal, but you'd need to compile the libraries first, then test some of the examples to verify it works.Assuming the application is intended to be a fullscreen one, without any desktop environment at all, only this one application running in the user interface, I'd definitely use Qt 5 Embedded.I personally like to construct the Qt UI in Python3 instead of C++, because that way the end users can modify/update the UI themselves. However, for a full-screen single-application case, I don't think it is as important, so in this particular case, I'd recommend C++ and Qt5 Embedded on EGL (OpenGL ES).

author: luiHS
author_rank: Frequent Contributor
timestamp: September 09, 2021, 01:43:02 am
content: Thanks, I think I will try QT again, but I will also try GTK + as an alternative.The problem is that the product I need to design will be commercial, so a free license, like QT's, requires that I give my development sources so that are freely accessible to anyone, and I can't do that.Do you know anything about SFML and WxWigdets?

author: Nominal Animal
author_rank: Super Contributor
timestamp: September 09, 2021, 07:41:48 am
content: Quote from: luiHS on September 09, 2021, 01:43:02 amNo. You can create a closed-source proprietary binary that links to LGPL libraries at run time. See e.g.here. You only need to provide the sources to those libraries (and only if you distribute them along with your program), not your own application.Seeherefor a summary of the Qt 5 modules and their licensing.In particular, you do not need to provide sources to your application that only links at run time to the LGPL libraries. (Run time dynamic linking is the default, too.)That is the key difference between GPL and LGPL: LGPL expressly clarifies that linking to a LGPL-licensed library does not create a derivative in the copyright law sense, and does not extend the LGPL license to the application linking to such a library.Quote from: luiHS on September 09, 2021, 01:43:02 amOnly enough to say I find Qt and GTK+ much more powerful for development on Linux.In practice, you should consider building your application so that it runs as a dedicated user account (because it sounds like a full-screen appliance of some sort). Depending on how you intend to distribute it –– as a package, or as a dedicated distribution on a provided 'Pi ––, you only need to provide sources of the open source packages (including the Qt libraries) used to build the environment; just make sure your binaries are dynamically linked (do not use-staticcompiler option!) to LGPL or similarly licensed libraries.Linking to the standard C and C++ libraries does not create a derivative of those, nor does using Linux syscalls.If you provide it as a package, compile your application using-Wl,-rpath,'$ORIGIN/../lib'as described inman 8 ld-linux, so that if your application is stored at/usr/lib/yourapp/bin/executable, the default location for dynamic libraries is/usr/lib/yourapp/lib/(or, to be precise,../lib/relative to the location of the binary). This way you can provide the specific versions of the Qt libraries (and whatever other libraries your application requires) and C++ runtime there, and use the system default standard C library. This yields a very portable way of creating proprietary binaries that work on many Linux distributions.

author: SiliconWizard
author_rank: Super Contributor
timestamp: September 09, 2021, 07:41:26 pm
content: C or C++? You'll need to make a choice. There's nothing like C/C++, even though that keeps being mentioned everywhere. Oh well, that's probably never going to sink in.So depending on the language, you'll have access to different libraries. QT is C++ of course, and using it from C, although probably possible with the right interface, would probably make no sense, and would be a lot of extra work. So with QT, of course, you'll have to use C++Now QT embedded was mentioned not long ago, and AFAIK, it now requires a commercial license. So QT embedded is out, unless you're ready to get a license.GTK is indeed another option. Contrary to QT, it can be used both from C and C++, there's official bindings for C++ (gtkmm).In both cases, you mentioned playing videos, and I don't think there is any video support in QT, but I may be mistaken as I haven't used it in ages. In which case you'd have to use yet another third-party library. For GTK, I think a video widget has been introduced in GTK4, so that would probably be an easy path. Graphics are done using Cairo on GTK - you can take a look. Cairo allows pretty antialised graphics and font rendering.In any case, I suppose you'll be using Linux on the RPi?One option, from your description, would also be to use some sort of "game engine". There are quite a few out there, and many will get you game-like UIs pretty easily. You could consider Allegro, OGRE...

author: PlainName
author_rank: Super Contributor
timestamp: September 09, 2021, 09:50:47 pm
content: Quote... would be inappropriate?

author: Karel
author_rank: Super Contributor
timestamp: September 09, 2021, 10:10:51 pm
content: Assuming you are using Raspbian for the OS, you only need to execute the following commands in order tobe able to compile your Qt C++ project:Code:sudo apt-get updatesudo apt-get install g++ make git qtbase5-dev-tools qtbase5-dev qt5-defaultNow, in your Qt project directory (the location of the source of your program) simply run:Code:qmakemakeThat's all.In other words, compiling a Qt program on a Raspberry Pi is no different than on a traditional pc with Debian or Ubuntu.

author: DiTBho
author_rank: Super Contributor
timestamp: September 09, 2021, 10:21:52 pm
content: OT:Quote from: Nominal Animal on September 08, 2021, 05:34:26 pmEGL is a good point forWayland, unfortunately it seems that only a few chips have EGL support.The RPI-v4 is on the list, but speaking of video cards ... it appears that only Radeon cards have it.Probably the RPI is a good choice from this point of view, I mean for embedded stuff

author: Karel
author_rank: Super Contributor
timestamp: September 10, 2021, 06:12:33 am
content: You don't need Qt for embedded, the normal Qt5 runs fine on an RPI4.It should run fine on an RPI3 as well but I haven't tested.No need to make things more complicated.

author: Nominal Animal
author_rank: Super Contributor
timestamp: September 10, 2021, 08:14:48 am
content: If we are as specific as possible, then there is no Qt Embedded in Qt 5, since it is replaced by QPA,Qt Platform Abstractionplugins. These plugins include LGPL-licensedqeglfs(for OpenGL ES) andqlinuxfb(for raw framebuffer on Linux), which are commonly called "Qt for embedded Linux".The difference to "standard" Qt libraries is that if you are running in Windows, you'll use theqdirect2dorqwindowsorqwinrt(Universal Windows Platform support) plugins;qandroidin Android;qxcborqwaylandin Linux,and so on. You only need a set of Qt libraries that enable the QPA plugin you need; thus far, I've compiled my own, but I haven't checked if the Raspbian ("Raspberry Pi OS") ones have qeglfs enabled (the qeglfs should use the accelerated OpenGL ES drivers on the Pi variants and other SBCs).Quote from: SiliconWizard on September 09, 2021, 07:41:26 pmNo,Qt for embedded Linuxis still licensed under LGPL. It's theQt for Device Creationthat is commercial, and you don't need that.Qt for embedded Linux is nothing but a configure time option when compiling the Qt libraries –– choosing the proper QPA plugin to use––, after all.The QPA plugins are part of theqt/qtbase.gitrepository, which is licensed under several different licenses, includingLGPLv3. Seesrc/plugins/platforms/for the QPA plugins included in Qt. You may even find the Qt libraries precompiled for various SBCs like 'Pis, with the appropriate QPA plugins already enabled, so you don't have to recompile anything.Quote from: SiliconWizard on September 09, 2021, 07:41:26 pmYou are indeed mistaken. Qt Multimedia widgets module does contain a video player; see theBSD 3-clause -licensedexamplehere.Both Qt Multimedia and Qt Multimedia widget modules are licensed under various licenses, including LGPL: see thesources.It seems to me you've read a bit too much Qt PR, since they obviously hope that developers buy the commercial licenses, even though they're rarely necessary.

author: SiliconWizard
author_rank: Super Contributor
timestamp: September 10, 2021, 05:09:37 pm
content: Quote from: Nominal Animal on September 10, 2021, 08:14:48 amI based my point on this:https://doc.qt.io/QtForMCUs/To be fair, it's strictly about Qt for MCUs - as this is what we discussed in another thread - and not "Qt Embedded" per se, so I got confused here. They seem pretty clear that you need a commercial license for this. But this is not needed for a RPi anyway, so you're right. You can use a standard Qt on a Linux distribution for the RPi anyway? No need to go "embedded" whatsoever.That said, I've always found Qt licensing to be something pretty obscure, and I don't doubt they maintain this impression on purpose.I would favor GTK myself when it comes to licensing. Also for technical reasons, as I'm a lot more familiar with it, and as Cairo allows nice graphics with little effort IMO. Also for the fact a wider range of languages are usable AFAIK. But that's just me. As I said, some game engine could be a better option for the OP - we don't know much about his project.

author: Nominal Animal
author_rank: Super Contributor
timestamp: September 10, 2021, 05:46:33 pm
content: Quote from: SiliconWizard on September 10, 2021, 05:09:37 pmRight. When talking about Qt 5 and later, the "embedded" just refers to a different plugin/backend (than Wayland/X11/etc.), that works directly on the framebuffer or display device, without any X server or similar support.For the application developer, it is the exact same libraries.Quote from: SiliconWizard on September 10, 2021, 05:09:37 pmTrue, that's why I qualified mine with "looks like an appliance". I was assuming some sort of an interactive kiosk system.SDLwould be another possibility. With SDL 1.2, one would have to link dynamically (LGPL). SDL 2 has a more permissive license, but doesn't have as many backends (only X11, Wayland, and raw framebuffer, AFAIK, on Linux).

author: nctnico
author_rank: Super Contributor
timestamp: September 11, 2021, 10:04:36 am
content: Quote from: luiHS on September 09, 2021, 01:43:02 amIf you don't take the Qt route then go for WxWidgets. I have been using wxwidgets for a long time (>10 years) for many projects. The beauty is that it is pretty straightforward to use and it abstracts a lot of OS specific stuff. For some projects I compile the embedded Linux (ARM) version from the same source as a Windows application to run on a PC. I do development under Linux.I've worked on GTK+ software as well but it is more low-level compared to Qt and WxWidgets and AFAIK GTK always uses its own widget set so you don't get a native look & feel if you use something else. IMHO software should adhere to the 'theme' the user has selected and not force something onto the user.The main problem I see with Qt is that it's license changes from commercial to non-commercial every few years. That is not something you can build a business on so I went for WxWidgets.Another option could be to use the Unreal engine. This supports cross compilation for Arm64 but AFAIK it only really supports Vulkan as a GPU backend. A couple of years ago I have managed to get the Android version to compile for Linux so it can use OpenGL-ES but the demo games didn't run so I never pursued it further.A quick google came up with this tutorial to get Unreal running on a Rpi4:https://www.raspberrypi.org/forums/viewtopic.php?t=293305

author: luiHS
author_rank: Frequent Contributor
timestamp: September 12, 2021, 01:16:46 pm
content: Thanks for the answers.Another issue is which IDE to use, if possible one with a graphical assistant for the forms, I think they are called RAD (rapid application development).For Qt, I am clear that it would be theQt Creator.Other IDEs that I know of are CodeBlocks, Geany, Visual Studio, Codelite, Eclipse.I'm interested in trying GTK and WxWidgets.For WxWidgets I thinkCodeBlockscan be used with thewxSmithplugin.For GTK I have read aboutGladeandAnjuta.Another possibility, as mentioned, is to use an engine to design games, although in my case, as I said, it is not a video game. I only need to play videos or visualize images, and superimposed on these images put some variable data (scores and others, with an artistic font), I also need to create a configuration menu with various data.

author: nctnico
author_rank: Super Contributor
timestamp: September 12, 2021, 01:48:34 pm
content: Creating forms in a tool may seem handy but in reality you will want to scale the controls to cater for various screen sizes which in turn means that you have to use code or rely on auto-scaling controls. I have stopped using tools to create forms for WxWidgets a long time ago. Making forms in code is pretty straightforward and you can alter things like alignment and spacing with a couple of defines.

author: PKTKS
author_rank: Super Contributor
timestamp: September 16, 2021, 11:07:15 am
content: Quote from: luiHS on September 08, 2021, 03:56:20 amWell pretty much the folks above detailed the 3 options: Qt/Gtk or wxWidgets.Much different among themselves and none of them arereallythat kind for dedicated framebuffers like video games or real time displays.I have used quite extensively the 3 of them mostly I prefer Gtk pure C API which can link to virtually anything you can think of despite templates hassle - e.g. templates may be a bless or a total curse in your life among compiler versions and compatible issuesIn these cases I usually fallback to what I think is the compromise:- dedicated double-buffers in Gtk - they work really nice despite the layer you have.- SDL based accelerated API (www.sdl.org)The latter can interface Gtk absolute seamlessDone sometime ago a simple DMM interface with FunctionGen SCOPE/Spectrum Analyser with SIGROK interface in almost a week using Gtk bindings only... almost real time tripple buffer threaded APINo template or STL hassle or problems with compiler oddsThe real argument is that Gtk version are easier to handle than the messy gtkmm or even the more messy Qt versions...An order of magnitude simpler faster SDL interface is also piece of cakeALAS interesting detail that pure C API allowed me to bind JACK transport streams to ALL instruments on these apps.. quite nice way to manage I/O under layerHope helpsPaul