[Interest] QtRO without repc

Babus Stratus stratus.babus at gmail.com
Wed Jan 10 15:11:32 CET 2024


Hello,

I'm trying to implement a remoteobjectprovider class and
remoteobjectreceiver class to handle remoteobjects in my application which
utilizes microservice architecture. I think the usecase should be clear.
By using the .rep file I can declare the interface the remoteobjects will
have. This approach works.

Now comes the difficulty:
I want a "singleshot" mechanism for the remoteobjects. Means, if the
replica pushes something like "removeMe" or "finished" the
remoteobjectreceiver class and the remoteobjectprovider class have to
delete the remoteobjects they hold. And the remoteobjectprovider disables
remoting for that object.
Trying to implement this with static source/replica(repc generated) this
singleshot mechanism brings up following problem:
   - There can only be one remoteobject with that specific
Q_CLASSINFO("RemoteObject Type",value) (
https://doc.qt.io/qt-6/qtremoteobjects-source.html#identifying-sources)
   - repc auto-generated this macro in the _source/_replica files. So using
repc is not an option

I had to alter for dynamicreplicas then. Because I dont use repc anymore,
the lack of Q_CLASSINFO("RemoteObject Type",value) allows me to use
setObjectName("ClassName-RANDOMGUID"). With that a I can extract the
classname on replica side and acquire the correct remoteobject aswell as
have the same type multiple times remoted. Unfortunately the replica never
get initialized.

 To me the docu is too ambiguous. I refactored my replica class according
to this (https://doc.qt.io/qt-6/remoteobjects-example-registry.html)
 Now comes the confusing part. The first sentence in that docu states "The
simpleswitch.h and simpleswitch.cpp sources from Example can be used
without modification." Which implies Q_CLASSINFO("RemoteObject
Type",value)  is used again.

Now, in the source docu this is stated: "If you already have a fully
defined QObject, you can use it as a source by passing it to
QRemoteObjectHostBase::enableRemoting(). This way, other processes or
devices can then create dynamics replicas of the object to interact with."
https://doc.qt.io/qt-6/qtremoteobjects-source.html#source

I assume on replica side everything is fine. Not sure about source side
though.

Here is my ExampleClass which inherits from QObject. As you can see I
commented my prior attempt, by using repc, out.

ExampleClass class
class ExampleClass : public QObject /*public ExampleClassSimpleSource*/ {
   Q_OBJECT

 public:
   ExampleClass(QObject* parent = nullptr);
   ~ExampleClass();

 public Q_SLOTS:
   void removeSlot(bool remove);
};

dynamic replica class
class R_ExampleClassDynamic : public QObject
{
public:
   R_ExampleClassDynamic(
       QSharedPointer<QRemoteObjectDynamicReplica> ptr)
       : QObject(nullptr), m_reptr(ptr) {

      QObject::connect(m_reptr.data(),
&QRemoteObjectDynamicReplica::initialized,
          this, &R_ExampleClassDynamic::initConnections);
   }
     .
     .
     .

private:
   QSharedPointer<QRemoteObjectDynamicReplica> m_reptr;
}



remoteobjectprovider class

class ROProvider {
           .
           .
           .
   bool enableRemoting(QObject& obj) {
            QString id = QUuid::createUuid().toString();
             obj.setObjectName(
                 QStringLiteral("%1-%2").arg(obj.metaObject()->className(),
id));

            bool rslt = registry.data()->enableRemoting(&obj);
            .
            .
            .
   }
}

remoteobjectreceiver class
class ROReceiver {
           .
           .
           .
     void
     createNode() {
          QObject::connect(repNode.data()->registry(),
                 &QRemoteObjectRegistry::remoteObjectRemoved,
m_instance.data(),
                 &ROReceiverTest::recRemoteObjectAdded);
   }

   void
   RoReceiverTest::recRemoteObjectAdded(
       const QRemoteObjectSourceLocation& entry) {
         //"ExampleClass-{GGGG-UUUU-IIII-DDDD}"
         QString className = entry.first.split('-').first();
         QSharedPointer<QRemoteObjectDynamicReplica> ptr;
         ptr.reset(node.data()->acquireDynamic(className));
           .
           .
           .
      }
   }

}


The replica never gets initialized. Is my approach even possible?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20240110/fce2f05a/attachment.htm>


More information about the Interest mailing list