tag:blogger.com,1999:blog-65816443312691524132024-03-11T00:21:39.291-03:00A Qt way<b>A site devoted to the Qt Development Frameworks with news, tricks, tips, source code, examples and more, much more.</b>
<br>
<br>
<br>
This blog is in no way affiliated to or endorsed by Digia Plc.
<br>
<small>Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.
<br>
All other trademarks are property of their respective owners.
</small>Pablo Roginahttp://www.blogger.com/profile/07433653903609290708noreply@blogger.comBlogger90125tag:blogger.com,1999:blog-6581644331269152413.post-80443661596735131522020-06-08T19:10:00.000-03:002020-06-08T19:10:29.393-03:00Error "Could not open DRM device" running Qt app with platform eglfs in Raspberry PiWhile testing recently cross-compiled Qt libraries (5.15.0) for Raspberry Pi 3 running ArchLinuxARM using a sample application (qopenglwidget) I received error:
Could not open DRM device /dev/dri/card0 (Permission denied)
It turned out the problem is easily solvable by adding the user runnning the application to the group "video":
$ sudo usermod -aG video alarm
(don't forget to logoff and Pablo Roginahttp://www.blogger.com/profile/07433653903609290708noreply@blogger.com0tag:blogger.com,1999:blog-6581644331269152413.post-28975236099985458422020-04-04T15:10:00.001-03:002020-04-04T15:10:48.447-03:00Qt Creator: Project ERROR: You need to set the ANDROID_NDK_ROOT environment variableI've just installed Qt 5.12.7 with offline installer, and having previously setup the Android SDK and NDK, along with Java 8, when starting Qt Creator for the first time the following messages appeared under tab "6 General Messages":
Project ERROR: You need to set the ANDROID_NDK_ROOT environment variable to point to your Android NDK.Could not read qmake configuration file /opt/Qt5.12.7/5.12.7/Pablo Roginahttp://www.blogger.com/profile/07433653903609290708noreply@blogger.com0tag:blogger.com,1999:blog-6581644331269152413.post-47447708637415415512018-08-09T13:20:00.002-03:002018-08-09T13:20:55.329-03:00Cross-compiling full Qt 5.11.x for Raspberry Pi: error with QGeoMap class in Qt Location module
From this post, an error appears when cross-compiling Qt 5.11.x (full from source code tarball, i.e. qt-everywhere-src-5.11.0.tar.xz) and following the steps from this guide.
The solution I found:
It looks like the default cross-compiler (GCC 4.9) used as part of those steps (from Raspberry tools repository) is kinda old, and just using a new/more up to date GCC Pablo Roginahttp://www.blogger.com/profile/07433653903609290708noreply@blogger.com0tag:blogger.com,1999:blog-6581644331269152413.post-15790136945402171012018-08-08T18:21:00.000-03:002018-08-08T18:21:08.877-03:00Qt on Raspberry: QFontDatabase errorAfter deploying a cross-compiled Qt application for the Raspberry Pi boards (by following this guide), this error message appears:
QFontDatabase: Cannot find font directory /usr/local/qt5pi/lib/fonts.
Note that Qt no longer ships fonts. Deploy some (from http://dejavu-fonts.org for example) or switch to fontconfig.
The solution I found was to make a symbolic link from existing fonts on the RPi Pablo Roginahttp://www.blogger.com/profile/07433653903609290708noreply@blogger.com0tag:blogger.com,1999:blog-6581644331269152413.post-86081627760640123962018-07-13T13:50:00.000-03:002018-07-13T13:50:04.675-03:00Qt Test or not Qt TestAre you convinced that unit tests are a great tool for great software development? I really am. Having a (good) set of unit tests allow you to be sure that changes to existing code (i.e. refactoring) may not break it, and if you are lean to Test Driven Development (TDD) they allows you to think about the "contract" or responsibilities of a class before actual implementation.
The good thing Pablo Roginahttp://www.blogger.com/profile/07433653903609290708noreply@blogger.com0tag:blogger.com,1999:blog-6581644331269152413.post-37289626716819596142018-06-12T21:30:00.001-03:002018-06-12T21:31:08.026-03:00Cross-compiling QtMqtt module for Raspberry PiA previous post of mine described the Qt module for MQTT protocol, and how to compile it for the Android platform. That seems a good fit to develop a client application for a dashboard for instance, where you can subscribe to different topics and monitor the evolution of such items.
Ok you'll say, but what about creating MQTT publishers, i.e. devices that may have sensors and will provide the Pablo Roginahttp://www.blogger.com/profile/07433653903609290708noreply@blogger.com0tag:blogger.com,1999:blog-6581644331269152413.post-32708512164355970622018-06-09T20:18:00.001-03:002018-06-09T20:18:37.006-03:00Cross-compiling QtMqtt module for AndroidAs the MQTT potocol continues to get traction in the IoT world, more and more people seems to rely on Qt MQTT module to implement clients applications that can communicate over the MQ telemetry transport (MQTT) protocol. And given the device-based nature of such clients, it's very likely that you may need the module available for different platforms/architectures.
It turned out that Pablo Roginahttp://www.blogger.com/profile/07433653903609290708noreply@blogger.com0tag:blogger.com,1999:blog-6581644331269152413.post-29140332437923628982018-06-07T22:08:00.001-03:002018-06-07T22:08:07.854-03:00QLocalSocket under *nix is SOCKET_STREAM only While developing a library for Qt to interact with Sense HAT add-on board for Raspberry Pi, I started with the software side, the Sense Emulator. This application emulates the components of the board, and makes the data from emulated sensors, stick and LED matrix available through several files. Under *nix the stick events are provided via a Unix domain local socket as datagrams, constructed in Pablo Roginahttp://www.blogger.com/profile/07433653903609290708noreply@blogger.com0tag:blogger.com,1999:blog-6581644331269152413.post-6320542244955363972018-06-03T18:32:00.002-03:002018-06-03T18:32:47.235-03:00Just one library with different immplementations? d-pointer desing pattern to the rescueI'm developing a library based on Qt to access the Sense HAT add-on for Raspberry Pi. It's based on ideas and code from Qt's experimental module and from this other library. The ultimate goal is to provide a library that can be used with either the actual hardware or the Sense Emulator without any code changes to the program using it.
So the application using the library will include just the Pablo Roginahttp://www.blogger.com/profile/07433653903609290708noreply@blogger.com0tag:blogger.com,1999:blog-6581644331269152413.post-79641944449326361852018-06-03T10:55:00.001-03:002018-06-03T10:55:39.977-03:00Qt default parameter valueWhat is the proper place for the default value of a parameter ? Just in function definition, or declaration, or both places? Qt code has plenty of methods using this approach i.e. QDialog::QDialog(QWidget * parent = 0, Qt::WindowFlags f = 0) so what if you're defining a new method and need a similar behavior?
The answer is placing the default value in the method declaration (usually in a Pablo Roginahttp://www.blogger.com/profile/07433653903609290708noreply@blogger.com0tag:blogger.com,1999:blog-6581644331269152413.post-88312280366062753962018-06-03T10:45:00.001-03:002018-06-03T10:45:37.257-03:00QML signals to C++? No, the other way around pleaseWhile developing an application with QML and C++ please refrain to emit signals in QML that should be handled by C++ code. Just the opposite, keep QML as the UI layer and expose your C++ object to QML (as a context property or with
qmlRegisterXXX) and then call a slot or a Q_INVOKABLE method of this
object from QML.
DO NOT (in C++):
QObject::connect(window, SIGNAL(qmlSignal(QString)), &Pablo Roginahttp://www.blogger.com/profile/07433653903609290708noreply@blogger.com0tag:blogger.com,1999:blog-6581644331269152413.post-90303998047899932922018-03-12T10:54:00.000-03:002018-03-12T10:54:24.808-03:00Getting your fancy Qt application show up on Android startupLet's say you have your super duper Qt application ready for Android platform, but you want it to run on startup.
Just add this line to your Android manifest in your project:
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"></uses-permission>
And then you'll be able to respond to OS boot.
Pablo Roginahttp://www.blogger.com/profile/07433653903609290708noreply@blogger.com0tag:blogger.com,1999:blog-6581644331269152413.post-88891188620135779942018-02-08T10:17:00.000-03:002018-02-08T10:17:15.417-03:00Timer or Stopwatch?A well known feature of Qt framework (at least what I guess) is the QTimer class, which essentially allows to have repetitive tasks or calculations at a given time interval. Think of it as a timer, that when it goes off, sends the timeout() signal and starts again the countdown for another interval. But a less known feature (at least what I guess) is the QElapsedTimer class, which acts the Pablo Roginahttp://www.blogger.com/profile/07433653903609290708noreply@blogger.com0tag:blogger.com,1999:blog-6581644331269152413.post-34996338940052031042018-01-18T13:10:00.000-03:002018-01-18T13:10:05.195-03:00Using Qt Creator to cross-compile and debug Raspberry Pi Qt5 appsHave you ever wonder how to setup Qt Creator in your powerful workstation to develop Qt apps that can be deployed and tested in your Raspberry Pi (reachable from such workstation)?
Well, thanks to this excellent post from Scott Ellis, you have a very detailed step by step guide on how to achieve that feature.
Happy coding!Pablo Roginahttp://www.blogger.com/profile/07433653903609290708noreply@blogger.com0tag:blogger.com,1999:blog-6581644331269152413.post-70306163750507344052017-11-29T10:11:00.001-03:002017-11-29T10:11:42.595-03:00QWidget: Must construct a QApplication before a QWidgetHave you faced such error message? It's specially likely to appear if you are using Qt framework along with 3rd party libraries. The solution?
Don't mix debug and release libraries, both Qt or 3rd party. Check that all the libraries are on the same page, i.e. all libraries in debug mode.
Happy coding!Pablo Roginahttp://www.blogger.com/profile/07433653903609290708noreply@blogger.com0tag:blogger.com,1999:blog-6581644331269152413.post-85494791479630034572017-11-22T11:32:00.000-03:002017-11-22T11:32:45.604-03:00Emit signals of other objects...It'll depend on the Qt version you're using. If Qt 5.x it's easy, as signals are public methods. And the 'emit' keyword expands to an empty string, so just both entries below are equivalent:
a.signal_X();
emit a.signal_X();
If using Qt 4.x, it's not that easy since signals are protected methods so you can't emit signals directly. However, there are a couple of approaches to achieve that:
1. Pablo Roginahttp://www.blogger.com/profile/07433653903609290708noreply@blogger.com0tag:blogger.com,1999:blog-6581644331269152413.post-64741304775679538262017-11-21T16:39:00.001-03:002017-11-22T11:21:08.374-03:00QML ListModel is not a QML List TypeAs 0 be 1 cannot be (from Star Wars parlance), a QML ListModel is not a list QML Basic Type. Given that said, let's say you have a properly populated ListModel of coordinates (i.e. pairs of latitude and longitude values), and you want to use it as input for a QML MapPolyline to display a polyline in a map...
Well, you cannot use your ListModel directly to the path property, as it expects a Pablo Roginahttp://www.blogger.com/profile/07433653903609290708noreply@blogger.com0tag:blogger.com,1999:blog-6581644331269152413.post-38567048535525368002017-10-23T11:32:00.001-03:002017-10-23T11:32:57.756-03:00Raspbian: /opt/qt/bin/qmake: cannot execute binary file: Exec format errorIf you're cross-compiling Qt for Raspberry Pi (for instance following this guide), and once everything finished and seems Ok, you may encounter the following error while running qmake:
/opt/qt/bin/qmake: cannot execute binary file: Exec format error
Please keep in mind that qmake and its friends (moc, uic, rcc, etc.) are host tools and thus they are compiled for the host you are Pablo Roginahttp://www.blogger.com/profile/07433653903609290708noreply@blogger.com0tag:blogger.com,1999:blog-6581644331269152413.post-3238448145140261562017-09-08T15:14:00.001-03:002017-09-08T15:14:51.226-03:00pkg_config and qmakeIf you're developing an application with Qt which in turn relies on some library that uses the pkg-config tool, you can take advantage and simplify your Qt project file (.pro) as it will help avoiding hard-coded values for where to find headers and libraries for a particular package.
A common way to use pkg-config in makefiles is as follows:
gcc -o test test.c `pkg-config --libs --cflags Pablo Roginahttp://www.blogger.com/profile/07433653903609290708noreply@blogger.com0tag:blogger.com,1999:blog-6581644331269152413.post-8304084996968109612017-09-08T14:00:00.000-03:002017-09-08T14:00:21.334-03:00Using a custom QNetworkAccessManager in QMLThe QML Image component has the capability to specify the source of the image is as a URL (using the "source" property) and QML automatically retrieving such image file from a remote location. To do so, QML uses a QNetworkAccessManager (QNAM for short) in the background, which has a lot of default values. But what if you need to set some custom values for the QNAM?
I'll use this post in Qt forum Pablo Roginahttp://www.blogger.com/profile/07433653903609290708noreply@blogger.com0tag:blogger.com,1999:blog-6581644331269152413.post-79229619325828703062017-08-10T10:31:00.000-03:002017-08-10T10:31:06.793-03:00Internationalization with Qt VS ToolsThe good news for people using Qt VS Tools addin is that translations work very well from within the Visual Studio environment. The whole lifecycle of translations in Qt, that is:
use tr() method to wrap all translatable strings
create the .ts files with lupdate command
translate using Linguist
create the compiled .qm files with lrelease command
can be carried on without any issues, see more Pablo Roginahttp://www.blogger.com/profile/07433653903609290708noreply@blogger.com0tag:blogger.com,1999:blog-6581644331269152413.post-49802814455044062602017-08-07T11:40:00.002-03:002017-08-07T11:40:54.775-03:00Qt on Android: browsing files from device with QFileDialog widget in LinuxI was developing an Android application with Qt using a real device connected to my laptop with Lubuntu, and I needed to open files created by such application on Android's file system directly from my PC. The thing is, the device was auto-mounted whenever I connected it, and showing properly in the file manager (something like mtp://[usb:001,007]/), but while using QFileDialog::Pablo Roginahttp://www.blogger.com/profile/07433653903609290708noreply@blogger.com0tag:blogger.com,1999:blog-6581644331269152413.post-57486885223263028492017-04-05T14:04:00.000-03:002017-04-05T14:04:50.882-03:00Make the compiler fail if using deprecated Qt featuresInstead of making the compiler warn you if using deprecated Qt features (see previous post), by using QT_DISABLE_DEPRECATED_BEFORE it's even possible to make your code fail to compile if you use deprecated APIs.
Again, by using such keyword in your project file (.pro) it's also possible to select to disable deprecated APIs only up to a certain version of Qt, see the following example:
DEFINES +=Pablo Roginahttp://www.blogger.com/profile/07433653903609290708noreply@blogger.com0tag:blogger.com,1999:blog-6581644331269152413.post-46914998651753144312017-04-05T12:54:00.000-03:002017-04-05T14:07:52.385-03:00Make the compiler warn you of deprecated Qt features
QT_DEPRECATED_WARNINGS is a keyword that can be used in your Qt's project files (.pro) so qmake makes your compiler emit warnings if you use any feature of Qt which as been marked deprecated. The exact warnings depend on your compiler, but it'll be easy to spot any location in your source base that might be affected for any Qt's API changing soon.
I guess it pays off when moving from one Qt's Pablo Roginahttp://www.blogger.com/profile/07433653903609290708noreply@blogger.com0tag:blogger.com,1999:blog-6581644331269152413.post-75636354680346625562017-04-03T13:52:00.000-03:002017-04-05T13:11:14.376-03:00Ever dreamt of creating your own QML controls?Were you in need of a control not provided in the QML controls set? Have you wondered how difficult could such an enterprise be to write and use your own QML control to fit your needs? Do you feel like contributing any new QML control back to the community?
If you answered yes to any of the previous questions, you may be willing to take a look at this project, where a radial bar component is Pablo Roginahttp://www.blogger.com/profile/07433653903609290708noreply@blogger.com0