Qt Remote Objects Source

Source Objects

A Remote Object Source is the QObject that is responsible for the implementation of the exposed API.

At a high level, you have a choice of using a QObject type directly as a source or defining the desired API in a .rep template for use with the repc compiler.

If you already have a fully defined QObject, it can become a Source simply by passing it to QRemoteObjectHostBase::enableRemoting(). This lets other processes/devices create a Replica of the object to interact with (see Remote Object Interaction). You can then instantiate QRemoteObjectDynamicReplicas of your object.

Letting repc generate a Source header file for your project (using the REPC_SOURCE variable) provides three options for implementing the desired API. If your class name was Foo, the options would be the following (see The rep file format for help in creating a rep file)

There is a <Type>SimpleSource class defined in the header, which provides basic getter/setter methods for each property and implements data members of the correct property type in the header. Here "<Type>" represents the class name from the .rep file, so if your class is of type "MyType" in the .rep file, there will be a MyTypeSimpleSource class declared in the generated header file. This is a fast way to get started using the API. To use this class, you need to inherit from this class and implement any defined slots (which are pure virtual in the generated header file). Whatever logic is needed to manage the exposed properties and emit signals would be added to the inheriting class as well.

If you need to hide the implementation details, you can use the <Type>Source class instead, which is the 2nd class declared in the header file. This class definition does not provide data members, and makes the getter/setter functions pure virtual as well. You have more flexibility in how you implement the class, although you need to write more code.

Finally, there is the <Type>SourceAPI class generated in the header. 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 desired API as the source. You will get compile-time warnings if the class does not provide the correct API, and using this class allows you to hide or convert properties or signal/slot parameters.

Note: The QObject API is never exposed. For instance, while a Replica will have a destroyed signal, the destroyed signal of the source is not propagated. The Source and each Replica are unique QObjects with their own connections. The API that is exposed is defined by the .rep template used by repc, or in the case of raw QObjects, all API elements defined in the inheritance chain from a specific ancestor. Unless you define Q_CLASSINFO("RemoteObject Type") in an ancestor, the QObject's parent is used. If Q_CLASSINFO("RemoteObject Type") is used, that class's API is the lowest level of API used.

Identifying Sources

Since more than one Source can be shared by a host node, 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/source types, or a static name() function for the SourceAPI type). If you pass your own QObject type to QRemoteObjectHostBase::enableRemoting(), the name will be determined using the following logic:

© 2018 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.