Qt 进程间通信

Qt提供了几种在 Qt 应用程序中实现 IPC (进程间通信) 的办法。

TCP/IP

跨平台 QtNetwork 模块提供使网络编程可移植且容易的类。它提供高级类 (如 QNetworkAccessManager , QFtp ) 使用特定应用程序级协议进行通信,和低级类 (如 QTcpSocket , QTcpServer , QSslSocket ) 为实现协议。

共享内存

跨平台共享内存类 QSharedMemory ,提供对操作系统共享内存实现的访问。它允许通过多线程和多进程,安全访问共享内存段。此外, QSystemSemaphore 可以用于控制系统共享资源的访问,及在进程之间通信。

D-Bus

The QtDBus 模块是仅 Unix 库,可使用 D-Bus 协议实现 IPC (进程间通信)。它扩展 Qt 的 信号和槽 mechanism to the IPC level, allowing a signal emitted by one process to be connected to a slot in another process. This D-Bus page has detailed information on how to use the QtDBus 模块。

Qt COmmunications Protocol (QCOP)

The QCopChannel class implements a protocol for transferring messages between client processes across named channels. QCopChannel is only available in Qt for Embedded Linux 。像 QtDBus module, QCOP extends Qt's 信号和槽 mechanism to the IPC level, allowing a signal emitted by one process to be connected to a slot in another process, but unlike QtDBus , QCOP does not depend on a third party library.