Inter-Process Communication

Qt supports many ways of communicating with other processes running in the same system or in different systems. There are basically three types of inter-process communication mechanisms:

  1. Synchronization primitives
  2. Exchanging of arbitrary byte-level data
  3. Passing structured messages

Synchronization primitives

Qt only provides one class for explicit inter-process synchronization: QSystemSemaphore. A QSystemSemaphore is like a QSemaphore that is accessible by multiple processes in 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; see the Native IPC Keys documentation for more information and limitations.

It is possible to use regular thread-synchronization primitives such as mutexes, wait conditions, and read-write locks, located in memory that is shared between processes. Qt does not provide any class to support this, but applications can use low-level operations on certain operating systems.

Other Qt classes may be used to provide higher-level locking, like QLockFile, or by acquiring a unique, system-wide resource. Such techniques include TCP or UDP ports or well-known names in D-Bus.

Byte-level data sharing

Using byte-level data, applications can implement any communication protocol they may choose. Sharing of byte data can be stream-oriented (serialized) or can allow random access (a similar condition to QFileDevice::isSequential()).

For serial communication, Qt provides a number of different classes and even full modules:

For random-access data sharing within the same system, Qt provides QSharedMemory. See the Shared Memory documentation for detailed information.

Structured message passing

Qt also provides a number of techniques to exchange structured messages with other processes. Applications can build on top of the byte-level solutions above, such as by using QJsonDocument or QXmlStreamReader / QXmlStreamWriter over HTTP to perform JSONRPC or XMLRPC, respectively, or QCborValue with QtCoAP.

Dedicated Qt modules for structured messages and remote procedure-calling include:

© 2024 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.