Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QtRO exposing QList<CustomType> as a property.
Forum Updated to NodeBB v4.3 + New Features

QtRO exposing QList<CustomType> as a property.

Scheduled Pinned Locked Moved Solved General and Desktop
qtremoteobject
2 Posts 1 Posters 947 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    batcher
    wrote on last edited by batcher
    #1

    Hello guys,

    I am new to the QtRO Module, I created a simple host node which expose a QList of custom types (POD (QString name, QUrl endpoint)), in the client side I am getting a replica in the default state. the QList data are not transferred to the replica from the source.

    ro.rep:

    #include <QtCore>
    
    POD Service(QString name, QUrl endpoint)
    
    class Services
    {
        PROP(QList<Service> services)
    }
    

    Server side:

    #include <QObject>
    #include "rep_ro_source.h"
    
    class RemoteListServer: public ServicesSimpleSource
    {
    public:
        RemoteListServer(QObject* parent = nullptr): ServicesSimpleSource(parent) {
        Service* s1 = new Service("service 1", QUrl("local:s"));
        Service* s2 = new Service("service 2", QUrl("local:s"));
        QList<Service>* l = new QList<Service>();
        l->push_back(*s1);
        l->push_back(*s2);
        this->setServices(*l);
        }
    };
    

    Server main.cpp:

    #include <QCoreApplication>
    #include <QRemoteObjectHost>
    #include "remotelistserver.h"
    
    int main(int argc, char *argv[])
    {
        QCoreApplication a(argc, argv);
    
        RemoteListServer server;
    
        QRemoteObjectHost host(QUrl("local:s"));
        host.enableRemoting(&server);
    
        qDebug() << "Services exposed : " << server.services().count();
    
        return a.exec();
    }
    

    Client side main.cpp:

    #include <QCoreApplication>
    #include <QRemoteObjectNode>
    
    #include "rep_ro_replica.h"
    
    int main(int argc, char *argv[])
    {
        QCoreApplication a(argc, argv);
    
        QRemoteObjectNode node;
        if(node.connectToNode(QUrl("local:s"))) {
            qDebug() << "Connnected";
        } else {
            qDebug() << "Not connected : " << node.lastError();
        }
    
        QScopedPointer<ServicesReplica> ptr;
        ptr.reset(node.acquire<ServicesReplica>());
    
        if(ptr.data()->isReplicaValid()) {
            qDebug() << "Services found : " << ptr.data()->services().count();
        } else {
            qDebug() << "Replica is not valid : " << ptr.data()->state();
        }
    
        return a.exec();
    }
    

    I am new to this framework so maybe I am doing something stupid, Thank you for your valuable help.

    1 Reply Last reply
    0
    • B Offline
      B Offline
      batcher
      wrote on last edited by
      #2

      OK, I finally figure it out, It was dumb, I had to wait till the replica get sync with the source, and this by handling the QRemoteObjectReplica stateChanged event. and it's all OK now.

      1 Reply Last reply
      1

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved