Example 3: Connections to Remote Nodes using a Registry¶
Describes how the Qt Remote Objects registry establishes connections between nodes. .. _qtro-example3: This example illustrates the use of a Registry to build the node topology. For simple networks, we use a
QUrl to create a direct connection between two nodes. For complex networks, we use a registry, where you use a different
QUrl to point both the host and replica nodes to the registry. For only two nodes, the benefits of using a registry are minimal. But, as the network grows, using a registry means that all nodes only need to connect to the registry via a single
QUrl . In comparison, with direct connections, nodes would have to maintain a list of QUrls for every single node that they link to.
Set up the Source¶
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:
from PySide6.QtCore import QCoreApplication from simpleswitch import * if __name__ == "__main__": a = QCoreApplication(argc, argv) srcSwitch = SimpleSwitch() regNode = QRemoteObjectRegistryHost(QUrl(QStringLiteral("local:registry"))) srcNode = QRemoteObjectHost(QUrl(QStringLiteral("local:switch")), 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()
Set up the Replica¶
The requestor object used for this example is the dynamic replica client discussed in Example 2 .
repNode = QRemoteObjectNode(QUrl(QStringLiteral("local:registry")))
When run together with the source-side example, the output is identical to Example 1 .
© 2022 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.