[Interest] Problems on RemoteObjects Model Replicas

Daesdemon daesdemon at free.fr
Mon Feb 24 08:13:40 CET 2020


Hi,
I have some problems with qt remote objects with models.

First the second time I require the model, it is already initialized but 
doesn't work correctly.

Second, the remote access of the model through proxy doesn't seem to 
work correctly too.

The following code, for example, result in this:


  "Standard Remote initialized" :
  NbRows: 2
  Available roles: QVector(0, 2)
  First Element: QVariant(QString, "Item1")


  "Remote copy already initialized" :
  NbRows: 0
  Available roles: QVector(0, 2)
  First Element: QVariant(Invalid)


  "RemoteModel through proxy" :
  NbRows: 2
  Available roles: QVector()
  First Element: QVariant(Invalid)

Did i missed something?

David



#include<QCoreApplication>

#include<QStringListModel>

#include<QDebug>

#include<QtRemoteObjects/QAbstractItemModelReplica>

#include<QtRemoteObjects/QRemoteObjectRegistryHost>

voidlogModel(constQString&message,QAbstractItemModelReplica*model)

{

qDebug()<<"\n"<<message<<":\n"

<<"NbRows:"<<model->rowCount()<<"\n"

<<"Availableroles:"<<model->availableRoles()<<"\n"

<<"FirstElement:"<<model->data(model->index(0,0),Qt::DisplayRole)<<"\n";

}

intmain(intargc,char*argv[])

{

//QLoggingCategory::setFilterRules(QStringLiteral("qt.remoteobjects*=true"));

QCoreApplicationa(argc,argv);

QStringListlist({"Item1","Item2"});

QStringListModelmodel(list);

QVector<int>roles({Qt::DisplayRole,Qt::EditRole});

QRemoteObjectRegistryHostregistry(QUrl(QStringLiteral("local:registry")));

registry.enableRemoting(&model,"model",roles);

QRemoteObjectNodenodeInternal;

nodeInternal.connectToNode(QUrl(QStringLiteral("local:registry")));

QAbstractItemModelReplica*romodel1=nodeInternal.acquireModel("model",QtRemoteObjects::PrefetchData,roles);

QObject::connect(romodel1,&QAbstractItemModelReplica::initialized,romodel1,[&]()

{

logModel("StandardRemoteinitialized",romodel1);

QAbstractItemModelReplica*romodel2=nodeInternal.acquireModel("model",QtRemoteObjects::PrefetchData,roles);

if(romodel2->isInitialized())

logModel("Remotecopyalreadyinitialized",romodel2);

});

//Newhostforproxy

QRemoteObjectHosthost(QUrl("local:service"));

host.proxy(QUrl(QStringLiteral("local:registry")));

QRemoteObjectNodenodeExternal;

nodeExternal.connectToNode(QUrl("local:service"));

QAbstractItemModelReplica*romodelproxy=nodeExternal.acquireModel("model",QtRemoteObjects::PrefetchData,roles);

QObject::connect(romodelproxy,&QAbstractItemModelReplica::initialized,romodelproxy,[=]()

{

logModel("RemoteModelthroughproxy",romodelproxy);

});

returna.exec();

}



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20200224/0b101fed/attachment.html>


More information about the Interest mailing list