Example 3: Connections to Remote Nodes using a Registry

Set up the Source

The simpleswitch.h and simpleswitch.cpp sources from Example can be used without modification. The difference is in the way a host node is created and connected to the registry:

main.cpp

#include <QCoreApplication>
#include "simpleswitch.h"

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);

    SimpleSwitch srcSwitch; // create SimpleSwitch

    QRemoteObjectRegistryHost regNode(QUrl(QStringLiteral("local:registry"))); // create node that hosts registry
    QRemoteObjectHost srcNode(QUrl(QStringLiteral("local:switch")), QUrl(QStringLiteral("local:registry"))); // create node that will host source and connect to registry
    //Note, you can add srcSwitch directly to regNode if desired.
    //We use two Nodes here, as the regNode could easily be in a third process.

    srcNode.enableRemoting(&srcSwitch); // enable remoting of source object

    return a.exec();
}

Set up the Replica

The requestor object used for this example is the dynamic replica client discussed in Example 2.

The only modification is in main.cpp: a Registry node is created to acquire a Replica:

    QRemoteObjectNode repNode(QUrl(QStringLiteral("local:registry")));

When run together with the source-side example, the output is identical to Example 1.

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