예제 3: 레지스트리를 사용한 원격 노드 연결
소스 설정
예제에 나온 simpleswitch.h 및 simpleswitch.cpp 소스는 수정 없이 그대로 사용할 수 있습니다. 차이점은 호스트 노드를 생성하고 레지스트리에 연결하는 방식에 있습니다:
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();
}복제본 설정
이 예제에서 사용되는 요청자 객체는 예제 2에서 다룬 동적 복제본 클라이언트입니다.
유일한 수정은 main.cpp 에 있습니다. 리플리카를 획득하기 위해 레지스트리 노드가 생성됩니다:
QRemoteObjectNode repNode(QUrl(QStringLiteral("local:registry")));소스 측 예제와 함께 실행하면 출력은 예제 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.