Unsolved Qt Remote Objects over TCP
-
Hello all,
I would like to know if Qt RO could be used to serve remotely a subclass of QObject that lives on another node on the LAN network. When all of my process run on the same machine, everything is fine. However, when they run on different machines, it doesn't seem to work.
Let say that I have two machines, one with IPa, the other one with IPb. The machine with IPa sets a Qt RO network, and the machine with IPb would like to access the Qt objects provided by the one with IPa. However, when I try to acquire a replica from this machine with IPb, the replica state is always Default, and it never enters to the state "Valid".
This is the code I'm using on IPa (it comes directly from Qt help about Qt RO):
AnObjectDerivedFromQObject objectInstance; // myInternalHost is a node only visible on the device... QRemoteObjectHost myInternalHost(QUrl("local:MyHost")); myInternalHost.enableRemoting(&objectInstance); // Regular host node, listening on port 12123, so visible to other // devices QRemoteObjectHost proxyNode(QUrl("tcp://127.0.0.1:12123")); // Enable proxying objects from nodes on the local machine's internal // QtRO bus proxyNode.proxy(QUrl("local:registry"));
And on the machine with IPb, I've implemented:
QSharedPointer<AnObjectDerivedFromQObjectReplica> replica; // NB: localhost resolves to a different ip address than proxyNode QRemoteObjectHost nodeOnRemoteDevice(QUrl("tcp://localhost:23234")); // This is as it is in the Qt doc // Connect to the target's proxyNode directly, or use a tcp registry... nodeOnRemoteDevice.connectToNode(QUrl("tcp://IPa:12123")); // Where IPa is the IP of the machine providing the actual object. // Because of the proxy, we can get the object over tcp/ip port 12123, // even though we can't connect directly to "local:MyHost" replica.reset(nodeOnRemoteDevice.acquire<AnObjectDerivedFromQObjectReplica>());
The replica state then never enters in the Valid state.
Could you please explain me what are my mistakes here? -
127.0.0.1
andlocalhost
both mean "this machine". If you never enter IPa how do you expect IPb to be able to connect? -
The argument given to connectToNode (the method that will connect to the host node on machine with IPa) is the IPa. The object nodeOnRemoteDevice is just another Qt RO network on the machine with IP address IPb.
-
The examples are actually quite confusing. Does anybody know what
local:switch
,local:registry
, etc. mean for a QUrl? I've never seen that and I can't find anything in the Qt documentation. Are these pipes? Or files? Both would explain why it works locally and not on distributed machines.