En esta página

Ejemplo 3: Conexiones a Nodos Remotos utilizando un Registro

Configurar la Fuente

Las fuentes simpleswitch.h y simpleswitch.cpp del Ejemplo pueden utilizarse sin modificaciones. La diferencia está en la forma en que se crea un nodo anfitrión y se conecta al registro:

main.cpp

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

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

    SimpleSwitch srcSwitch; // create SimpleSwitch

    // Create node that hosts registry:
    QRemoteObjectRegistryHost regNode(QUrl(QStringLiteral("local:registry")));

    // Create node that will host source and connect to registry:
    QRemoteObjectHost srcNode(QUrl(QStringLiteral("local:replica")),
                              QUrl(QStringLiteral("local: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();
}

Configurar la réplica

El objeto solicitante utilizado para este ejemplo es el cliente de réplica dinámico descrito en el Ejemplo 2. La única modificación se encuentra en .

La única modificación está en main.cpp: se crea un nodo de Registro para adquirir una Réplica:

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

Cuando se ejecuta junto con el ejemplo del lado fuente, el resultado es idéntico al del Ejemplo 1.

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