[Interest] Qt Remote Objects QOBJECT_REPLICA Macro

Stottlemyer, Brett (B.S.) bstottle at ford.com
Fri Jun 16 15:51:21 CEST 2017

On 6/15/17 5:39 AM, "Andrew Ialacci" <andrew at dkai.dk> wrote:
> I am trying to have the repc compiler automatically generate a repc file from an existing QObject. 
>   According to the documentation below this should be possible using the QOBJECT_REPLICA macro. 
>   However, there is no information on how to use it or where to put it in a project.

Right, the documentation is lagging behind the code.  We are still working on that.

In the .pro file you need a couple things.
QT += remoteobjects

REP_FILES = myClass.h

First line adds QtRO to the project and makes the other macros available.  Then QOBJECT_REP will set up repc to
generate the .rep definition for the QOBJECT, and REPC_REPLICA will take that and set up the generation of the
QtRO header files for your type.

I say “set up the generation”, as this defines additional elements to the Makefile, but you need to use the output
in code in order to have those elements run.  So, in some .cpp file, add:

#include "rep_myClass_replica.h"

If you do a shadow build, that header file will be created in the shadow build directory with the other build
products, which is good because it is a generated file, but a little confusing as it isn’t with the source code.

>    I’ve tried looking through the QtRO source on code.qt.io but there are no references to the macro there either.

Yeah, my team has been mostly creating .rep files directly rather than starting with QObject files, but I’m sure this
is useful functionality for an existing codebase.

The only example is in tests/auto/pods.

>   Hope this was the right place to ask.

Sure, this is a fine place to ask.


More information about the Interest mailing list