2

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?

heitho
  • 61
  • 1
  • 7
  • Strange task... Why don't use [Dynamic Replica](https://doc.qt.io/qt-5/remoteobjects-example-dynamic-replica.html) ? Seems it is designed specifically for this. – Vladimir Bershov Dec 12 '19 at 09:17
  • I saw the example on the qt website, but it looked like the same behavior, as the server side is not changed to use dynamic replica – heitho Dec 12 '19 at 09:21
  • Could you edit your question to explain the conditions of the problem. What domain functionality do you want to implement? – Vladimir Bershov Dec 12 '19 at 09:36

0 Answers0