I'm trying to setup a remote object for a given class. The class return pointer to internal objects.
class A
{
...
func(){ };
}
class B
{
std::vector<A> AObjects;
...
A *addObject(){}
}
I created the rep file like this
class A
{
SLOT(func())
}
class B
{
SLOT(A* addObject())
}
This causes errors because the generated code tries to serialize A to transfer it to the cient/replica side. What I want is a RemoteObject of A to get transferred to call func remotely from the client side. The number of A Object depends on the remote calls of addObject.
Is there a way to get the such a system with qt remote objects?
One way I could imagine is to set the returntype in B to the generated Replica class.
class A
{
SLOT(func())
}
class B
{
SLOT(AReplica addObject())
}
But then the generated code must be available also at server side and the headers need to be in the right inclusion order.
Addition: Replica objects are not serializable either.
Edit:
To get the desired behavior I changed the rep-file
class Object
{
SLOT(print(QString& i_oString));
};
class ObjectGenerator
{
SLOT(QString genObj())
};
The implementation of the server looks like this:
QString Server::genObj()
{
auto obj = new Obj();
auto objRep = QString::number(reinterpret_cast<size_t>(obj)); //pinter as unique string reference
m_oHost.enableRemoting(obj, objRep);
qDebug() << "generated object: " << objRep << endl;
return objRep;
}
The client can now trigger object generations and retrieve the replica
auto obj = reptr->genObj();
obj.waitForFinished();
auto rep = m_node.acquire<ObjectReplica>(obj.returnValue());
QObject::connect(this, SIGNAL(printSignal(QString&)), rep, SLOT(print(QString &)));
In this implementation I need to wrap the client side to get a usable interface.
Is there a more qt-like way of doing this?