QtRO exposing QList<CustomType> as a property.



  • 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.



  • 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.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.