Eight Ways to Up Your Qt on Embedded Linux Game

Homepage Eight Ways to Up Your Qt on Embedded Linux Game

There are plenty of resources out there to explain how to develop with Qt for embedded software, and for embedded Linux systems. For developers, it’s a popular choice and it’s easy to understand why. Qt comes with APIs out of the box making development faster, has a range of different development accelerators to keep things moving, and allows for cross-compiling and on-device debugging, too.

At Witekio we’ve long been fans of Qt and have used the framework to develop applications for connected devices from consumer kitchens to groundbreaking MedTech. Our engineers have put Qt up against competitors in head-to-head tests to find the best framework for developing a rich UX on an IoT device (spoiler: Qt performed very well!). Our engineers know Qt inside and out, and Witekio is proud to partner with Qt in the development of innovative human-machine interfaces.

It shouldn’t come as a shock, then, to learn that our teams have figured out how to get the most out of Qt – and they’re happy to be able to share some of their time-saving best practices with you.

Here are eight tips to help you work faster, more efficiently, and deliver your Qt code on time.

1/ Strip Binaries

Everyone wants to move faster and a simple way to accelerate your work with Qt is to strip your binaries.

Compiled binary files usually contain information for debugging. This is useful for finding bugs or debugging in general, but it is not at all necessary for executing the program. A stripped binary, on the other hand, is a binary file without all the debugging symbols. By definition, a stripped binary is smaller than its unstripped cousin and so, when it comes time to upload the code, everything moves faster. It’s an easy way to buy yourself time and accelerate your development efforts.

2/ Incremental Deployment

You’re ready to deploy your code: are you going to push the whole lot or is there a better way?

If your project is composed of different executables, libraries and resources, incremental deployment instructs QtCreator to upload only those that were modified since the last time you deployed your project. As with a stripped binary, this makes for a smaller file and a faster deployment, saving you time and bandwidth, and lifting efficiency, too – look for the option in QtCreator.

3/ Check Dependencies if Code Doesn’t Update

Some people avoid incremental deployment at all costs. Why? Because they have tried it and it just didn’t work. Is the problem with incremental deployment as a strategy? Probably not.

Instead, it is likely that there is a dependency that you might have forgotten about that is causing bugs to flourish. You might have updated Library A and pushed the changes but forgotten that it is dependent on Library B which you didn’t push. By recalling and checking your dependencies you can push updates faster without running into bugs. In particular, when you have an executable or shared library linking to a static library, make sure that a static library is included in your qmake PRE_TARGETDEPS variable.

4/ Enable Ccache

Ccache is a great tool to speed up your Qt compiling – and enabling it is as easy as flipping a switch!

Ccache is a small and simple tool with an oversized impact. It caches previous compilations of your code and then – when you go to compile again – detects what has changed and what has not. If it is possible to reuse what is stored in the Ccache cache, it will, and this avoids recompiling unchanging source code repeatedly. The result is a compilation that is significantly faster than working from scratch each time, and yet another way to up the efficiency of your Qt game.

Developing Linux with Qt?

5/ QtCreator Android Configuration File

If you use QtCreator with Qt for Android kits, you may need to configure QtCreator to tell it which are the versions you want to use (android tools, ndk, etc.) for a given Qt version. Under Linux, this can be configured in file ~/.config/QtProject/qtcreator/android

6/ Build Qt for Windows Using Wine

A lot of times when you are developing for Windows on a Linux machine you’ll work with a virtual machine – but did you know you can build and run your Qt for windows application on Linux using wine?

Wine is, a compatibility layer capable of running Windows applications on several POSIX-compliant operating systems, such as Linux. While best known for enabling gamers to play their PC games on other operating systems, with Wine installed you can also work with Qt for Windows in your familiar Linux environment.

7/ Logging Categories in Qt

Now, this isn’t going to change your world, but it will make your job just a little bit easier.

Logging is an essential part of Qt and most any other application. Logging makes it easier to figure out what is going on during development and debugging so that, when you get that message and you don’t quite know (or remember!) what it means, it’s a breeze to figure it out.

Qt offers a convenient feature, called QLoggingCategory, that allows you to dynamically modify which statements should be shown. More importantly, Qt framework itself uses them extensively, so if you wish to make Qt a bit more verbose regarding a specific topic, you can use the QT_LOGGING_CONF environment variable at run time, no need to rebuild your application or Qt for that.

8/ Config for Visibility (Windows/Linux)

One of the great things about Qt is its portability. You can run it on Linux, on Android, on Linux Embedded and on Windows, too. Using the same codebase on Linux and Windows can be a big time-saver, but there can be issues, too.

Qt5 introduced the new signal/slot connection syntax, which has several advantages. However, if you use the new syntax with signals and slots from different libraries under Windows, you may have noticed that the slots are not being called – this can be fixed by using the Q_DECL_IMPORT/Q_DECL_EXPORT directives.

But note, too, that this is a bit tricky since if some Q_DECL_XXX statements are missing under Windows, the link will fail, while it will succeed under Linux. So, if you develop most of your codebase under Linux, you might discover tons of missing Q_DECL_XXX statements when you switch to Windows.

One solution for that is to use the CONFIG += hide_symbols statement, so that even under Linux, missing Q_DECL_XXX statements will trigger some link errors.

If you configure for variability – and it’s just a matter of directing the compiler not to export the symbols by default – you can ensure that your Linux and Windows builds run equally well.

Nicolas  Boulicault  - Software Engineer
07 January 2022