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. Problems on RemoteObjects Model Replicas
Forum Updated to NodeBB v4.3 + New Features

Problems on RemoteObjects Model Replicas

Scheduled Pinned Locked Moved Unsolved General and Desktop
1 Posts 1 Posters 195 Views 1 Watching
  • 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.
  • D Offline
    D Offline
    Daes
    wrote on last edited by Daes
    #1

    Hi,
    I already post this question on interest list but get no answers.

    I have some problems on 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" : OK
    NbRows: 2
    Available roles: QVector(0, 2)
    First Element: QVariant(QString, "Item1")

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

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

    Did i missed something?

    Daes

    
    #include <QCoreApplication>
    
    #include <QStringListModel>
    
    #include <QDebug>
    
    #include <QtRemoteObjects/QAbstractItemModelReplica>
    
    #include <QtRemoteObjects/QRemoteObjectRegistryHost>
    
    void logModel(const QString& message,QAbstractItemModelReplica* model)
    
    {
    
        qDebug() << "\n" << message << ": \n"
    
                 << "NbRows:" << model->rowCount() << "\n"
    
                 << "Available roles:" << model->availableRoles() << "\n"
    
                 << "First Element:" << model->data(model->index(0,0),Qt::DisplayRole)<< "\n";
    
    }
    
    int main(int argc, char *argv[])
    
    {
    
        // QLoggingCategory::setFilterRules(QStringLiteral("qt.remoteobjects* = true"));
    
        QCoreApplication a(argc, argv);
    
        QStringList list({"Item1","Item2"});
    
        QStringListModel model(list);
    
        QVector<int> roles({Qt::DisplayRole,Qt::EditRole});
    
        QRemoteObjectRegistryHost registry(QUrl(QStringLiteral("local:registry")));
    
        registry.enableRemoting(&model,"model",roles);
    
        QRemoteObjectNode nodeInternal;
    
        nodeInternal.connectToNode(QUrl(QStringLiteral("local:registry")));
    
        QAbstractItemModelReplica* romodel1 = nodeInternal.acquireModel("model",QtRemoteObjects::PrefetchData,roles);
    
        QObject::connect(romodel1,&QAbstractItemModelReplica::initialized,romodel1,[&]()
    
        {
    
            logModel("Standard Remote initialized",romodel1);
    
            QAbstractItemModelReplica* romodel2 = nodeInternal.acquireModel("model",QtRemoteObjects::PrefetchData,roles);
    
            if (romodel2->isInitialized())
    
                logModel("Remote copy already initialized",romodel2);
    
        });
    
        // New host for proxy
    
        QRemoteObjectHost host(QUrl("local:service"));
    
        host.proxy(QUrl(QStringLiteral("local:registry")));
    
        QRemoteObjectNode nodeExternal;
    
        nodeExternal.connectToNode(QUrl("local:service"));
    
        QAbstractItemModelReplica* romodelproxy = nodeExternal.acquireModel("model",QtRemoteObjects::PrefetchData,roles);
    
        QObject::connect(romodelproxy,&QAbstractItemModelReplica::initialized,romodelproxy,[=]()
    
        {
    
            logModel("RemoteModel through proxy",romodelproxy);
    
        });
    
        return a.exec();
    
    }
    
    1 Reply Last reply
    0

    • Login

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