- Qt 6.11
- All Overviews
- Inter-process communication in Qt
- Qt 6.11.2 Reference Documentation

Networking and Connectivity ◦ Qt's Undo Framework

# Inter-process communication in Qt

Qt provides several ways to implement inter-process communication (IPC) in applications. The IPC functionality in Qt includes:

- Synchronizing processes and sharing resources
- Exchanging byte-level data locally or over a network
- Sharing replicated Qt objects between processes or systems
- Passing structured messages or remote procedure calls (RPC)
- Using M2M industry standard protocols for IoT and industrial systems

Many of the IPC mechanisms are for networked devices and use network protocols such as TCP, UDP, and HTTP. The Networking and Connectivity overview covers the networking topic in more detail.

Qt supports structured data formats such as JSON, XML, Protobuf, and CBOR. For more information about structured data, see the Data processing and I/O overview pages.

## Synchronizing processes and sharing resources

For processes that share local resources or systems that synchronize actions and data, you can use system semaphores and shared memory. These functionalities are part of the Qt Core module.

Qt provides classes for inter-process synchronization, including QSystemSemaphore. Similar to QSemaphore, it is accessible by multiple processes on the same system. It is globally identified by a key, which in Qt is represented by the QNativeIpcKey class. Additionally, depending on the OS, Qt may support multiple different backends for sharing memory.

For a thorough explanation, see the following pages:

- Synchronization Primitives
- Shared Memory
- Native IPC Keys

### Shared memory

The cross-platform shared memory class, QSharedMemory, provides access to the operating system's shared memory implementation. It allows safe access to shared memory segments by multiple threads and processes. Additionally, QSystemSemaphore controls access to resources shared by the system and enables communication between processes.

## Creating child processes

The QProcess class can start external programs as child processes and communicate with them. It provides an API for monitoring and controlling the state of the child process. QProcess gives access to the input and output channels of the child process by inheriting from QIODevice.

## Sharing Qt objects among remote processes or systems

The Qt Remote Objects module provides a remote object mechanism to enable devices and processes to share Qt objects. It uses a Source object that is synchronized with Replica objects using an intermediary Node. These Replicas are essentially proxies that mirror the Source object's properties, signals, and slots so that remote processes can interact with the object without direct knowledge of the network transport.

## Sending messages with Remote Procedure Calls (RPC)

Remote Procedure Call (RPC) is a high-level mechanism that abstracts the underlying network communication. With RPC, a client can call functions that execute on a remote server as if they were local function calls. Multiple languages provide support for RPC technologies, simplifying implementation in complex systems that use multiple programming languages.

The Qt GRPC module implements Remote Procedure Calls (RPC) using the gRPC protocol. gRPC is a widely adopted framework for sending messages in serialized format, most commonly using HTTP/2 for efficient network communication. gRPC is well-suited for communication in modular microservices and low-latency applications such as chat and streaming platforms.

## Using M2M industry standard protocols

Machine-to-Machine (M2M) industry protocols are specific to systems that are under strict resource constraints such as sensors and automation systems. Often they are specific to the industry and use cases such as manufacturing, healthcare, and environmental monitoring. These systems are often low power and have limited processing capabilities.

The Qt MQTT module provides MQTT functionality to Qt applications. MQTT is a protocol that uses the publish and subscribe pattern to send information within a system. In an MQTT system, a broker manages the sending and receiving to clients. Clients can be publishers, subscribers, or both. MQTT is effective in low-bandwidth and high-latency environments such as industrial and manufacturing systems.

The Qt CoAP module provides Constrained Application Protocol (CoAP) to Qt applications. CoAP is a protocol that uses UDP and RESTful principles to send information within constrained systems. CoAP is especially designed to take advantage of compact datagram messages and low overhead.

The Qt OPC UA module provides OPC UA to Qt applications. It uses a client and server IPC mechanism for industrial systems. OPC UA is for complex systems and has built-in security measures.

You can implement hybrid systems with MQTT, CoAP, and OPC UA. For example, you can implement the cloud communication in MQTT, the main system with OPC UA, and connect the individual sensors and devices using CoAP.

One protocol may be widely adopted in a specific industry and its development ecosystem. The system architecture and the messages are also formed differently. For example, MQTT mainly uses TCP while CoAP uses UDP. Consequently, MQTT can use TLS and CoAP can use DTLS for secure transfers.

## Using the D-Bus protocol

The Qt D-Bus module is a Unix-only library you can use to implement IPC using the D-Bus protocol. It extends Qt's Signals and Slots mechanism to the IPC level, allowing a signal emitted by one process to be connected to a slot in another process.

## Using sessions in applications

On Linux/X11, Windows, and macOS, Qt provides support for session management. Sessions allow events to be propagated to processes, for example, to notify when a shutdown occurs. The processes and applications can then perform any necessary operations such as saving open documents. For more information, see the Session Management page.

## IPC security considerations

Because data is transferred among processes or systems, you need to consider privacy and security issues. Attackers can intercept data within networks and foreign processes can monitor data within a system.

These are some security measures that you can implement:

- Use encryption when sending or receiving data. See Secure Sockets Layer (SSL) Classes.
- Use strong authentication and authorization mechanisms. See Qt Network Authorization.
- Validate and process untrusted data. See Handling Untrusted Data.
- Set rate limits and monitor traffic to prevent misuse.
- Incorporate salting or nonce techniques to protect against monitoring and replay attacks.
- Update your environment to fix security vulnerabilities.

The Security in Qt page discusses Qt's security policies and measures. Qt modules may implement different protocols and therefore may have additional security considerations.

Networking and Connectivity ◦ Qt's Undo Framework