Qt远程对象源

Qt Remote Objects Source

Qt远程对象源

At a high level, you can choose to use a QObject type directly as a source; or you can define the desired API in a .rep template for use with the repc compiler.

​在较高层次上,可以选择直接将QObject类型用作源;或者可以在.rep模板中定义所需的API,以便与repc编译器一起使用。​

If you already have a fully defined QObject, you can use it as a source by passing it to QRemoteObjectHostBase::enableRemoting(). This way, other processes or devices can then create dynamics replicas of the object to interact with.

​如果已经有一个完全定义的QObject,可以通过将它传递给QRemoteObjectHostBase::enableRemoting()来将其用作源。这样,其他进程或设备就可以创建对象的动态副本进行交互。

For more information, see Remote Object Interaction.

​有关更多信息,请参见远程对象交互。

Letting repc generate a source header file for your project, using the REPC_SOURCE variable, provides three different options to implement the required API.

​让repc使用repc_source变量为项目生成源头文件,可以提供三种不同的选项来实现所需的API。

Suppose your class name is Foo, you then have the following options:

假设你的类名是Foo,那么以下选项:

For more details on how to create a .rep file, see The rep file format.

​有关如何创建.rep文件的更多详细信息,请参阅rep文件格式。

There is a <Type>SimpleSource class defined in the header, which provides the basic getter/setter methods for each property and implements data members of the correct property type in the header. "<Type>" here represents the class name from the .rep file, so if your class is of type "MyType" in the .rep file, then the generated header file will have a MyTypeSimpleSource class declared. This is a quick way to get started using the API. To use this class, you need to write a class that inherits from it and implement any slots defined, which are marked as pure virtual in the generated header file. You need to add the necessary logic to manage the exposed properties and emit signals, to your class as well.

头文件中定义了一个<Type>SimpleSource类,它为每个属性提供了基本的getter/setter方法,并在头文件中实现了正确属性类型的数据成员。这里的“<Type>”表示.rep文件中的类名,因此,如果类在.rep文件的类型为“MyType”,那么生成的头文件将声明一个MyTypeSimpleSource类。这是开始使用API的快速方法。要使用这个类,需要编写一个继承它的类,并实现任何定义的插槽,这些插槽在生成的头文件中标记为纯虚拟。还需要向类添加必要的逻辑来管理公开的属性并发出信号。

If you need to hide your implementation details, use the second class declared in the header file, the <Type>Source class. This class' definition does not provide data members, and also makes the getter/setter functions pure virtual. While you may need to write more code, using this class gives you more flexibility in your implementation.

如果需要隐藏实现细节,请使用头文件中声明的第二个类,即<Type>Source类。这个类的定义不提供数据成员,也使getter/setter函数成为纯虚函数。虽然可能需要编写更多的代码,但使用此类可以在实现中提供更大的灵活性。

The third class generated in the header is <Type>SourceAPI. This is a templated class, for use specifically by the templated version of QRemoteObjectHostBase::enableRemoting(), which allows you to use any QObject that supports the required API as the source. Use this class to hide or convert properties or signal/slot parameters. If your implementation does not provide the correct API, there will be compile-time warnings.

​头文件中生成的第三个类是<Type>SourceAPI。这是一个模板化类,专门用于模板化版本的QRemoteObjectHostBase::enableRemoting(),它允许使用任何支持所需API的QObject作为源。使用此类隐藏或转换属性或信号/槽参数。如果实现没有提供正确的API,将出现编译时警告。

Note: Replicas and sources both derive from QObject; but their QObject API is never exposed. For instance, while a replica has a destroyed signal, the source's destroyed signal is not propagated. The source and each of its replica are unique QObjects with their own connections and lifetimes. Instead, the API that is exposed is defined by the .rep template used by repc. In the case of raw QObjects, all API elements are defined in the inheritance chain from a specific ancestor. The QObject's parent is always used, unless you define Q_CLASSINFO("RemoteObject Type") in an ancestor. If you use Q_CLASSINFO("RemoteObject Type"), that class's API is the lowest level of API used.


注:副本和源都来自QObject;但是他们的QObject API从未被公开。例如,当复制品有一个被破坏的信号时,源的被破坏信号不会传播。源及其每个副本都是唯一的QObjects,具有自己的连接和生命周期。相反,公开的API是由repc使用的.rep模板定义的。在原始QObjects的情况下,所有API元素都是在继承链中从特定的祖先定义的。除非在祖先中定义了Q_CLASSINFO(“远程对象类型”),否则始终使用QObject的父对象。如果使用Q_CLASSINFO(“RemoteObject类型”),则该类的API是所使用的API的最低级别。

Identifying Sources

识别来源

Because a host node can share more than one source, each source requires a name. All repc-generated headers include a way for the node to determine the class name: Q_CLASSINFO for replica, simplesource, or source types; or a static name() function for the SourceAPI type. If you pass your own QObject type to QRemoteObjectHostBase::enableRemoting(), the name is determined using the following logic:

​因为主机节点可以共享多个源,所以每个源都需要一个名称。所有repc生成的头文件都包含一种节点确定类名的方法:Q_CLASSINFO用于副本、simplesource或源类型;或者SourceAPI类型的静态name()函数。如果将自己的QObject类型传递给QRemoteObjectHostBase::enableRemoting(),则使用以下逻辑确定名称:

  • A name can optionally be passed to QRemoteObjectHostBase::enableRemoting(). If provided, that name is used.
  • ​可以选择将名称传递给QRemoteObjectHostBase::enableRemoting()。如果提供,则使用该名称。
  • If the object or any of its ancestors has Q_CLASSINFO of type "RemoteObject Type" defined, that type name is used.
  • ​如果对象或其任何祖先定义了“RemoteObject type”类型的Q_CLASSINFO,则使用该类型名称。
  • If the QObject's objectName is set, then it is used.
  • ​如果设置了QObject的objectName,则使用它。
  • If none of the above are available, the call to QRemoteObjectHostBase::enableRemoting() fails, returning false.
  • ​如果以上都不可用,则调用QRemoteObjectHostBase::enableRemoting()失败,返回false。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值