例 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.