本页内容

QRemoteObjectReplica Class

一个在 Qt Remote Objects 网络上与 Qt API 进行交互(但未实现该 API)的类。更多内容...

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

QRemoteObjectDynamicReplica 以及QRemoteObjectRegistry

公共类型

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

属性

公共函数

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)

详细说明

远程对象副本(Remote Object Replica)是另一个远程对象(QObject ,称为源对象)的QObject 代理。初始化后,副本可视为源对象的“潜伏副本”。也就是说,源对象上任何对属性(Q_PROPERTY )的更改,或源对象发出的任何信号,都将由所有副本对象进行更新或发出。 延迟主要源于相关操作系统的进程调度以及网络通信延迟。只要副本已完成初始化且通信未中断,变更的接收及其顺序均得到保证。

通过isInitialized 和state 属性(以及相应的initialized() /stateChanged() 信号),可以确定Replica的状态。

虽然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 : State

返回副本状态。

该属性保存副本的QRemoteObjectReplica::State 。

访问函数:

QRemoteObjectReplica::State state() const

通知器信号:

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 。

注意: 这是 state 属性的获取器 函数。

另请参阅 isInitialized 。

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

每当副本的状态在“QRemoteObjectReplica::State ”之间切换时,都会发出此信号。

状态的变化分别由state 和oldState 表示。

注意: 这是属性state 的通知器 信号。

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

bool QRemoteObjectReplica::waitForSource(int timeout = 30000)

阻塞调用,该调用将等待副本初始化完成,或直至timeout (单位为毫秒)超时。如果调用完成时副本已初始化,则返回true ;否则返回false 。

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

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

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