QRemoteObjectReplica Class

在远程对象(Remote Objects)网络上与 Qt API 交互(但不实现)的类。更多

头文件: #include <QRemoteObjectReplica>
CMake: find_package(Qt6 REQUIRED COMPONENTS RemoteObjects)
target_link_libraries(mytarget PRIVATE Qt6::RemoteObjects)
qmake: QT += remoteobjects
继承: QObject
继承于

QRemoteObjectDynamicReplicaQRemoteObjectRegistry

公共类型

enum State { Uninitialized, Default, Valid, Suspect, SignatureMismatch }

属性

  • node : QRemoteObjectNode*
  • state : const State

公共功能

bool isInitialized() const
bool isReplicaValid() const
QRemoteObjectNode *node() const
virtual void setNode(QRemoteObjectNode *node)
QRemoteObjectReplica::State state() const
bool waitForSource(int timeout = 30000)

信号

void initialized()
void notified()
void stateChanged(QRemoteObjectReplica::State state, QRemoteObjectReplica::State oldState)

详细说明

远程对象副本是另一个QObject (称为对象)的QObject 代理。一旦初始化,副本可被视为对象的 "潜在副本"。也就是说,对象上Q_PROPERTY 的每次更改或源对象发出的信号都会被所有副本对象更新/发出。任何操作系统的进程调度和网络通信延迟都会造成延迟。只要副本已初始化且通信未中断,就能保证接收到更改并按顺序进行更改。

通过isInitializedstate 属性(以及相应的initialized()/stateChanged() 信号),可以确定副本的状态。

虽然Qt Remote Objects (QtRO) 会处理Replica对象的初始化和同步,但在幕后还有许多步骤可能会失败,这在单进程 Qt 应用程序中是不会遇到的。有关使用远程对象网络时如何处理此类问题的建议,请参阅故障排除

成员类型文档

enum QRemoteObjectReplica::State

该枚举类型指定了与QRemoteObjectReplica 状态相关的各种状态代码:

常量描述
QRemoteObjectReplica::Uninitialized0DynamicReplica 的初始值,即在连接到源之前对副本一无所知。
QRemoteObjectReplica::Default1静态副本的初始值,.rep 文件中设置的任何默认值都可用,以便在必要时使用。
QRemoteObjectReplica::Valid2表示副本已连接,具有良好的属性值,并可与之交互。
QRemoteObjectReplica::Suspect3如果初始化后与源的连接丢失,则会出现错误状态。
QRemoteObjectReplica::SignatureMismatch4如果与源建立了连接,但源和副本不是来自同一个 .rep,则会出现错误状态(仅适用于静态副本)。

属性文档

node : QRemoteObjectNode*

该属性包含一个指向从该对象获取的节点的指针。

访问功能:

QRemoteObjectNode *node() const
virtual void setNode(QRemoteObjectNode *node)

[read-only] state : const State

返回副本状态。

该属性保存副本QRemoteObjectReplica::State

访问功能:

QRemoteObjectReplica::State state() const

Notifier 信号:

void stateChanged(QRemoteObjectReplica::State state, QRemoteObjectReplica::State oldState)

成员函数 文档

[signal] void QRemoteObjectReplica::initialized()

副本初始化后会发出该信号。初始化的副本已设置了所有属性值,但尚未发出任何属性变更通知。

另请参阅 isInitialized() 和stateChanged()。

bool QRemoteObjectReplica::isInitialized() const

如果该副本已使用对象的数据初始化,则返回true 。否则返回false

另请参见 state()。

bool QRemoteObjectReplica::isReplicaValid() const

如果该副本已初始化并与托管node 有有效连接,则返回true 。否则返回false

另请参阅 isInitialized().

[signal] void QRemoteObjectReplica::notified()

一旦副本初始化且所有属性更改通知都已发出,就会发出该信号。

有时,将属性更改作为事件来响应是非常有用的。例如,您可能希望在发生特定属性更改时显示用户通知。然而,当副本首次成为QRemoteObjectReplica::Valid 时也会触发该用户通知,因为所有的属性更改信号都会在此时发出。这并不总是可取的,而notified 允许开发人员区分这两种情况。

QRemoteObjectReplica::State QRemoteObjectReplica::state() const

返回副本当前的state

注: 属性状态的获取函数。

另请参阅 isInitialized

[signal] void QRemoteObjectReplica::stateChanged(QRemoteObjectReplica::State state, QRemoteObjectReplica::State oldState)

每当副本的状态在QRemoteObjectReplica::State 之间切换时,就会发出该信号。

状态的变化用stateoldState 表示。

注: 属性state 的通知信号。

另请参阅 state() 和initialized()。

bool QRemoteObjectReplica::waitForSource(int timeout = 30000)

阻塞调用,等待副本初始化或timeout (毫秒)到期。如果调用完成时副本已初始化,则返回true ,否则返回false

如果timeout 为-1,则此函数不会超时。

另请参阅 isInitialized() 和initialized()。

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