Qt Remote Objects

远程对象概念

QtRO (Qt Remote Objects) 是为 Qt 开发的 IPC (进程间通信) 模块。此模块扩展了 Qt 的现有功能,使进程 (或计算机) 之间能够轻松交换信息。

Qt 使这种信息能够交换的关键特征之一是对象 API (由其特性、信号及槽定义) 与该 API 实现之间的区别。QtRO 的目的是满足期望 API,即使 true QObject 在不同进程中。称为槽的对象复本 ( Replica 在 QtRO) 被转发到 true 对象 ( 在 QtRO) 为处理。各 Replica (复本) 接收 Source (源) 的更新,要么是特性改变,要么是发射信号。

A Replica 是轻量级代理对于 object, but a Replica supports the same connections and behavior of QObjects, which makes it usable in the same way as any other QObject that Qt provides. Behind the scenes, QtRO handles everything that's necessary for the Replica to look like its Source.

Note that Remote Objects behave differently from traditional Remote Procedure Call (RPC) implementations, for example:

  • In RPC, the client makes a request and waits for the response.
  • In RPC, the server doesn't push anything to the client unless it's in response to a request.
  • Often, the design of RPC is such that different clients are independent of each other: for instance, two clients can ask a mapping service for directions and get different results.

While it is possible to implement this RPC-style behavior in QtRO, as Sources without properties, and slots that have return values, QtRO hides the fact that the processing is really remote. You let a node give you the Replica instead of creating it yourself, possibly use the status signals ( isReplicaValid() ), but then interact with the object like you would with any other QObject 基类型。

使用案例:GPS

Consider a sensor such as a Global Positioning System (GPS) receiver. In QtRO terms:

  • would be the process that directly interacts with the GPS hardware and derives your current location.
  • The location would be exposed as QObject properties; the periodic updates to the location would update these properties and emit property changed signals.
  • Replicas would be created in other processes and would always know your current location, but wouldn't need any of the logic to compute the location from the sensor data.
  • Connecting to the location changed signal on the Replica would work as expected: the signal emitted from the Source would trigger the signal emission on every Replica.

使用案例:访问打印机

Consider a service that provides access to a printer. In QtRO terms:

  • would be the process controlling the printer directly.
  • The ink levels and printer status would be monitored by QObject properties. Updates to these properties would emit property changed signals.
  • The key feature -- being able to print something -- needs to be passed back to the printer. Incidentally, this aligns with the Qt slot mechanism, which QtRO uses as the way for Replicas to make calls on the Source. In effect, properties and signals go from Source to Replicas; slots go from Replica to Source.
  • When a print request is accepted, the printer status would change, triggering a change in the status property. This would then be reported to all Replicas.

指南

参考

许可

Qt Remote Objects 在商业许可下是可用的来自 Qt 公司 。此外,它是可用的根据 GNU LGPL (次一般公共许可) 第 3 版 ,或 GNU GPL (一般公共许可) 第 2 版 。见 Qt 许可 进一步了解细节。