Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Architecture for QML Sensor Application
simmue last edited by
at the moment I am working on a project on Raspberry Pi, where I have several sensors connected via i2c and want to show their values inside a Qt QML application.
I abstracted the different sensor-types into respective Sensor-classes. Those classes also hold logic to ask for current values via i2c bus. They also hold the latest value.
The sensor-objects live in one common, but separate Thread to decouple from UI.
When a sensor-object did an update, it stores the latest value and then emits a signal that this very sensor updated its value.
Then, an object ("SensorHub") in mainThread which is a custom QML type, gets one of its slots executed. (it has one slot for every sensor signal). In that slot I do two things:
- SensorHub has a member variable for every sensor value. That gets updated, or if the values are equal nothing is done.
Is this process correct or can I optimize it?
It works, but I think it might be too much overhead to throw that many signals.
All the signals that I use provide the new sensor value as parameter to the slot. Is this good practise or does it induce further overhead? Is there an alternative way to have the current sensor values available to the QML visualization?
As I am a student I would be happy to hear tips, tricks and hints to get to learn more about Qt/QML!
Have a nice day :-)