Inter-Process Communication#

An overview of Qt’s inter-process communication functionality

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 isSequential() ).

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

  • Pipes and FIFOs: QFile

  • Child processes: QProcess

  • Sockets: QTcpSocket, QUdpSocket (in Qt Network)

  • HTTP(S): QNetworkAccessManager (in Qt Network) and QHttpServer (in Qt HTTP Server)

  • CoAP(S): QCoapClient (in Qt CoAP)

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:

  • Qt D-Bus

  • Qt Remote Objects

  • Qt WebSockets