Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Problems on RemoteObjects Model Replicas



  • 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();
    
    }
    

Log in to reply