Article
QP & Qt in Embedded Systems
Beyond the Display: Combining QP and Qt in Distributed Embedded Systems
Modern industrial and medical electronic products increasingly incorporate sophisticated graphical user interfaces alongside embedded systems responsible for controlling physical processes. A single product may need to coordinate robotic motion, acquire measurement data, monitor operating conditions, maintain historical records, communicate with external systems, and present an intuitive touchscreen interface.
These functions have substantially different computational and timing requirements.
A robotic control system, for example, may need to respond to changes in sensor inputs within precisely defined time constraints. Its graphical interface, on the other hand, may be responsible for rendering complex visualizations, managing operator interactions, recording historical data, and communicating with cloud-based services. These activities generally do not require the same degree of real-time determinism.
Although these functions belong to the same product, there is no inherent reason they must execute on the same processor or even within the same operating system.
The QP/C++ active object framework from Quantum Leaps and the Qt application framework provide complementary capabilities that make them particularly interesting when developing this type of distributed electronic system.
Separating application behavior from presentation
The principle of separating application logic from its graphical representation is well established in software engineering. Architectural patterns such as Model-View-Controller (MVC) and Model-View-ViewModel (MVVM) recognize that the internal behavior and state of an application need not be inseparably coupled to the way that information is presented to the user.
Qt provides extensive support for this separation through Qt Quick, QML, its property binding mechanisms, and its integration with C++ application code.
QML allows graphical interfaces to be described declaratively. Visual components can respond to changes in application data without requiring the underlying application to explicitly manage every graphical operation.
QP approaches application architecture from a different direction. It provides an event-driven execution framework in which independent software components, known as active objects, communicate asynchronously through events. The behavior of these active objects can be represented using hierarchical state machines.
These approaches complement one another.
QP provides a framework for describing how a system behaves, while Qt provides a framework for presenting information about that behavior and facilitating interaction with it.
When combined appropriately, neither framework needs to assume responsibilities that are more naturally addressed by the other.
When logical separation becomes physical separation
Consider an industrial robotic system consisting of two principal electronic assemblies:
- A master control unit responsible for controlling the machinery.
- A graphical head unit providing the operator interface.
The master control unit may be implemented using an embedded microcontroller operating under a real-time operating system or a real-time execution kernel. Its responsibilities may include motor control, sensor acquisition, machine sequencing, fault detection, and coordination of time-critical operations.
The graphical head unit may be implemented using a more powerful application processor running embedded Linux. Its responsibilities may include touchscreen interaction, graphical visualization, historical data storage, network communication, and the management of removable storage devices.
The two assemblies may communicate over Ethernet, a serial interface, or another suitable communication medium.
Although physically separated, these assemblies form a single electronic product from the perspective of the operator.
The architectural challenge is to preserve that logical unity without introducing unnecessary dependencies between the application components executing on the two processors.
Extending an event-driven architecture across processors
One of the distinguishing characteristics of QP is its support for publish-subscribe communication between active objects.
An active object can publish an event describing a change in system state, the completion of an operation, the availability of new measurement data, or the occurrence of a fault. Other active objects interested in that information can subscribe to the corresponding event signal.
The publisher does not need to know which active objects consume the information or how those active objects use it.
Within a conventional QP application, this communication occurs within a single execution environment. However, the same architectural principle can be extended across physically separated processors through the introduction of communication proxies.
Consider the following conceptual architecture:
GRAPHICAL HEAD UNIT
Embedded Linux
+---------------------------------------+
| |
| Qt Quick / QML |
| Touchscreen Interface |
| | |
| Qt / QP Integration |
| | |
| QP Active Object Framework |
| |
| Operator Interaction |
| Screen Flow Management |
| Data Logging |
| Configuration Management |
| External Communications |
| | |
| Communication Proxy |
+------------------|--------------------+
|
Ethernet / Serial
|
+------------------|--------------------+
| Communication Proxy |
| | |
| QP Active Object Framework |
| |
| Machine Sequencing |
| Motion Coordination |
| Sensor Acquisition |
| Fault Management |
| Real-Time Control Coordination |
| | |
| Hardware Interfaces |
| |
+---------------------------------------+
MASTER CONTROL UNIT
Real-Time Embedded System
A communication proxy on each processor provides a boundary between the local event-driven application and the communication transport connecting the two assemblies.
Selected events published within one execution environment can be communicated to the other environment, where corresponding local events can be made available to interested active objects.
From the perspective of an application component, consuming an event originating on a remote processor can therefore resemble consuming an event originating elsewhere within the local application.
The communication link becomes an architectural infrastructure component rather than a dependency distributed throughout the application software.
It is important to recognize that QP’s native publish-subscribe mechanism is local to its execution environment. Extending that mechanism across processors requires additional application infrastructure. The proxy design pattern provides a means of introducing that infrastructure while preserving the event-driven character of the application.
Keeping real-time control independent of the graphical interface
Physical separation is particularly valuable when different portions of an application have different timing requirements.
The master control unit of a robotic system may be responsible for operations with deadlines measured in microseconds or milliseconds. Missing these deadlines could adversely affect machine performance, stability, or safety.
Graphical interfaces introduce a substantially different computational workload. Rendering animations, accessing filesystems, processing touchscreen input, and communicating with external services can introduce variable execution times.
A general-purpose operating system such as Linux provides considerable flexibility for implementing these functions, but a conventional Linux graphical application does not inherently provide the timing guarantees required by certain machine-control functions.
By locating time-critical control functions on a dedicated processor, the master control unit can operate independently of the graphical interface’s computational workload.
The communication link between the head unit and the master control unit consequently does not need to participate directly in the machine’s fastest control loops.
An operator may initiate a movement through the touchscreen, for example, but the execution and timing of that movement remain the responsibility of the master control unit.
Similarly, the master control unit can publish information about the progress of an operation without depending on the graphical interface to receive and render every update before continuing.
The graphical interface supervises and interacts with the machine rather than becoming an indispensable participant in its real-time control algorithms.
This separation does not eliminate the need for timing analysis. Supervisory commands, communication failures, and fault indications may still have defined latency requirements. Those requirements, however, can be considered independently of the tighter deadlines associated with direct machine control.
The graphical head unit is more than a display
An important aspect of this architecture is that the graphical head unit need not be implemented merely as a remote display terminal.
By incorporating QP into the head unit itself, the Linux-based application can contain its own collection of active objects and hierarchical state machines.
These active objects can manage functionality that is logically associated with the operator interface or the broader information-management requirements of the product.
Examples include:
- Operator interaction and workflow management.
- Screen navigation and application operating modes.
- Historical measurement data and operational records.
- Product configuration and user preferences.
- Data import and export using removable storage.
- Report generation.
- Network connectivity and cloud integration.
- Software update coordination.
- Communication with external information systems.
These functions may have considerable behavioral complexity without requiring the real-time characteristics of the master control unit.
For example, exporting historical machine data to a USB flash drive may involve detecting the storage device, evaluating its availability, managing the export operation, reporting progress, handling errors, and notifying the operator when the operation is complete.
Such behavior can be represented naturally using an active object and a hierarchical state machine without embedding the operation’s sequencing and error handling within the graphical interface.
Similarly, a data-logging active object can subscribe to operational information originating from the master control unit without requiring the Qt graphical interface to participate in the logging operation.
The graphical interface can present the state of these activities while their underlying behavior remains independently managed by the application.
Qt and QML as the presentation layer
Qt Quick and QML provide a particularly useful presentation environment for this type of architecture.
Qt offers graphical rendering capabilities, hardware-accelerated graphics on supported platforms, touchscreen interaction, animation, reusable graphical components, and integration with a broad collection of application libraries.
QML provides declarative mechanisms for describing graphical elements and their relationships to application data.
An operating status indicator, for example, may change color in response to the machine’s reported operating state. A graphical representation of a robotic assembly may respond to changes in position data. A historical trend display may update as new measurement records become available.
These visual behaviors do not necessarily require the graphical components themselves to be implemented as QP state machines.
Instead, the graphical interface can observe an application-facing representation of the relevant system state through Qt’s property, notification, and data model mechanisms.
The QP application manages the underlying operational behavior, while QML manages the visual representation of that behavior.
This does not preclude the use of state machines for screen flow or operator workflows. A multistep calibration procedure, a machine setup sequence, or a controlled maintenance workflow may have sufficient behavioral complexity to warrant explicit representation using a hierarchical state machine.
However, the state machine responsible for managing the workflow need not directly implement the rendering of the corresponding screens.
The distinction is between managing the behavior of the application and managing the graphical representation of that behavior.
There is also an important execution boundary between Qt and QP. Both frameworks have their own event-processing mechanisms and concurrency considerations. The integration must respect Qt’s thread-affinity requirements, particularly when exchanging information with graphical objects and data models.
One source of information, multiple consumers
A useful consequence of publish-subscribe architecture is that information generated by the master control unit can serve multiple independent purposes.
Consider a machine that periodically publishes operating data, including motor position, temperature, operating mode, production counts, and diagnostic information.
After this information becomes available within the head unit, several application components may independently consume it.
| Application component | Use of published information |
|---|---|
| Graphical interface | Presents current operating conditions to the operator. |
| Data logger | Maintains historical records of machine operation. |
| Diagnostic subsystem | Records faults and relevant operating conditions. |
| Reporting subsystem | Produces operational and production reports. |
| Cloud communications | Communicates selected information to external services. |
| Removable storage manager | Supports exporting operational records. |
The master control unit does not need to implement separate communication mechanisms for each of these consumers.
Nor does the graphical interface need to act as an intermediary through which all machine information passes.
Each application component can consume the information relevant to its responsibilities.
Additional capabilities can potentially be introduced without modifying the original producer of the information, provided that the existing event interfaces contain the necessary data and maintain compatible semantics.
This is a particularly valuable property for products that evolve over an extended commercial lifecycle.
A machine initially designed with local data logging may later require remote monitoring, fleet management, predictive maintenance, or integration with a manufacturing information system.
An appropriately structured event-driven architecture provides a foundation for introducing these capabilities without unnecessarily restructuring the machine-control application.
Sharing application interfaces across execution environments
When both the master control unit and the graphical head unit use QP/C++, there are opportunities to share portions of the application source code across otherwise dissimilar computing platforms.
Event definitions, data types, operating state enumerations, and certain platform-independent application components may be common to both environments.
The master control unit may execute on a microcontroller without a conventional filesystem or graphical environment, while the head unit may execute on a Linux application processor with gigabytes of memory and access to sophisticated graphical and networking libraries.
Despite these differences, both systems can participate in a common event-oriented application architecture.
Shared event definitions help establish a consistent vocabulary through which the distributed components of the system communicate.
An event describing the completion of a machine operation should have the same application-level meaning regardless of which processor receives it.
However, sharing C++ data structures does not automatically establish a portable communication protocol. Differences in processor architecture, memory representation, software version, and communication transport must still be considered.
The application-level event interface and its representation on the communication link are related but distinct architectural concerns.
Maintaining that distinction allows the distributed application to preserve common semantics without becoming unnecessarily dependent on the implementation details of a particular processor or communication medium.
Communication transparency has limits
Although the proxy design pattern can abstract many characteristics of the communication link, a distributed system cannot be assumed to behave identically to a single-processor application.
Communication introduces latency, finite bandwidth, possible message loss, and the possibility that one portion of the system becomes unavailable while another continues operating.
A command originating at the graphical head unit may be delayed, rejected, or received after the operating state of the machine has changed.
Similarly, information displayed on the touchscreen may no longer represent the current state of the master control unit if communication has been interrupted.
These conditions introduce requirements involving:
- Communication availability and connection state.
- Data freshness and synchronization.
- Event ordering and delivery guarantees.
- Command acceptance and execution status.
- Compatibility between independently released firmware and software.
- Communication security and authorization.
- Recovery following interrupted communication.
- Safe machine behavior when supervisory communication is unavailable.
Not every event has the same requirements.
Periodically published operating data may tolerate occasional loss, whereas an operator command or an important fault indication may require stronger delivery and confirmation semantics.
The communication architecture must reflect these differences.
Furthermore, the master control unit should retain authority over the physical operations for which it is responsible. A request originating from the graphical interface does not supersede the operating constraints, safety conditions, or interlocks enforced by the machine-control application.
Where safety-related functions are involved, the architecture must satisfy the applicable safety requirements independently of the convenience provided by the graphical interface or communication abstraction.
The objective of communication transparency is to reduce unnecessary software coupling, not to conceal the fundamental characteristics and failure modes of a distributed system.
Architectural flexibility throughout product development
Perhaps the most significant advantage of this approach is that it allows the logical organization of the application to be considered separately from its physical deployment.
An event-driven application can be organized around functional responsibilities rather than around the assumption that every function must execute on a particular processor.
During product development, decisions concerning processor selection, computational resources, operating systems, graphical capabilities, and communication interfaces may evolve.
Some products may ultimately consolidate their functionality onto a single processor. Others may distribute functionality across multiple processors or electronic assemblies.
A well-defined event-driven architecture can reduce the extent to which these physical deployment decisions require changes to the underlying application logic.
For a family of industrial machines, for example, several products may share a common graphical head unit while employing different master control units appropriate to their respective mechanical systems.
Conversely, a common master control architecture may be used with different graphical interfaces depending on the requirements of individual products.
This flexibility has implications for software reuse, product customization, hardware obsolescence, verification, and long-term product maintenance.
It also allows processor selection to be driven more directly by the computational, electrical, economic, and real-time requirements of each portion of the system.
Conclusion
QP and Qt address complementary aspects of electronic product software architecture. QP provides a structured framework for asynchronous communication, active objects, and hierarchical state machines, while Qt provides a sophisticated environment for graphical presentation and user interaction.
By combining these frameworks with an appropriately designed communication abstraction, the separation between application behavior and presentation can extend beyond software modules to physically distributed computing environments. Real-time machine control can remain on processors selected for deterministic operation, while graphical interfaces, data management, and external connectivity can take advantage of the capabilities of Linux-based application processors.
The significance of this architecture extends beyond the choice of software frameworks. It provides a means of organizing an electronic product around its functional responsibilities rather than its physical computing boundaries.
At Wolff Electronic Design, we consider these architectural relationships during the early stages of electronic product development. By establishing clear boundaries between real-time control, application behavior, information management, and graphical presentation, we seek to develop systems that remain maintainable, extensible, and adaptable throughout their commercial lifecycle.
