模型视图客户端

开发一个非常简单的客户端程序,用于显示服务器上的内容和更改。

这就是与Model-View 服务器配套的客户端程序。

    QRemoteObjectNode node(QUrl(QStringLiteral("local:registry")));
    node.setHeartbeatInterval(1000);

我们首先创建一个QRemoteObjectNode 并将其连接到本地计算机上的注册表。我们还设置了一个heartbeat interval 。心跳用于检测与源的连接是否中断。在本例中,由于所有流量都是本地流量,它将检测服务器是否已关闭。

    QScopedPointer<QAbstractItemModelReplica> model(node.acquireModel(QStringLiteral("RemoteModel")));

然后,我们将acquire 包含所有数据的模型。在本例中,我们希望从所连接的远程对象网络中获取名为RemoteModel 的模型。

    QTreeView view;
    view.setWindowTitle(QStringLiteral("RemoteView"));
    view.resize(640,480);
    view.setModel(model.data());
    view.show();

最后,我们在一个非常基本的应用程序中显示该模型。

示例项目 @ code.qt.io

© 2025 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.