QRemoteObjectNode 类

Qt Remote Objects 网络节点。 更多...

头: #include <QRemoteObjectNode>
CMake: find_package(Qt6 COMPONENTS RemoteObjects REQUIRED)
target_link_libraries(mytarget PRIVATE Qt6::RemoteObjects)
qmake: QT += remoteobjects
实例化: Node
继承: QObject
继承者: QRemoteObjectHostBase

公共类型

enum ErrorCode { NoError, RegistryNotAcquired, RegistryAlreadyHosted, NodeIsNoServer, ServerAlreadyCreated, …, ListenFailed }
  RemoteObjectSchemaHandler

特性

公共函数

  QRemoteObjectNode (const QUrl & registryAddress , QObject * parent = nullptr)
  QRemoteObjectNode (QObject * parent = nullptr)
ObjectType * acquire (const QString & name = QString())
QRemoteObjectDynamicReplica * acquireDynamic (const QString & name )
QAbstractItemModelReplica * acquireModel (const QString & name , QtRemoteObjects::InitialAction action = QtRemoteObjects::FetchRootSize, const QList<int> & rolesHint = {})
void addClientSideConnection (QIODevice * ioDevice )
bool connectToNode (const QUrl & address )
int heartbeatInterval () const
QStringList instances () const
QStringList instances (QStringView typeName ) const
QRemoteObjectNode::ErrorCode lastError () const
QRemoteObjectAbstractPersistedStore * persistedStore () const
void registerExternalSchema (const QString & schema , QRemoteObjectNode::RemoteObjectSchemaHandler handler )
const QRemoteObjectRegistry * registry () const
QUrl registryUrl () const
void setHeartbeatInterval (int interval )
virtual void setName (const QString & name )
void setPersistedStore (QRemoteObjectAbstractPersistedStore * persistedStore )
virtual bool setRegistryUrl (const QUrl & registryAddress )
bool waitForRegistry (int timeout = 30000)

信号

void heartbeatIntervalChanged (int heartbeatInterval )
void remoteObjectAdded (const QRemoteObjectSourceLocation & loc )
void remoteObjectRemoved (const QRemoteObjectSourceLocation & loc )

重实现保护函数

virtual void timerEvent (QTimerEvent *) override

详细描述

QRemoteObjectNode 类提供的条目指向 QtRemoteObjects 网络。网络可以简单到 2 节点 (或任意复杂的一组进程和设备)。

QRemoteObjectNode 没有其它节点可连接的 URL,因此只能获得复本。无法共享源对象 (仅 QRemoteObjectHost and QRemoteObjectRegistryHost 节点可以共享)。

节点可以相互直接连接使用 connectToNode ,或者它们可以使用 QRemoteObjectRegistry 以简化连接。

QRemoteObjectRegistry 是连接到注册 URL 的每个节点都可用的特殊复本。它知道如何连接到网络中的每个 QRemoteObjectSource 对象。

另请参阅 QRemoteObjectHost and QRemoteObjectRegistryHost .

成员类型文档编制

enum QRemoteObjectNode:: ErrorCode

此枚举类型指定各种错误代码所关联的 QRemoteObjectNode 错误:

常量 描述
QRemoteObjectNode::NoError 0 没有错误。
QRemoteObjectNode::RegistryNotAcquired 1 无法获得注册。
QRemoteObjectNode::RegistryAlreadyHosted 2 注册已定义且正托管 Source (源)。
QRemoteObjectNode::NodeIsNoServer 3 给定 QRemoteObjectNode 不是主机节点。
QRemoteObjectNode::ServerAlreadyCreated 4 主机节点已初始化。
QRemoteObjectNode::UnintendedRegistryHosting 5 An attempt was made to create a host QRemoteObjectNode and connect to itself as the registry.
QRemoteObjectNode::OperationNotValidOnClientNode 6 The attempted operation is not valid on a client QRemoteObjectNode .
QRemoteObjectNode::SourceNotRegistered 7 The given QRemoteObjectSource is not registered on this node.
QRemoteObjectNode::MissingObjectName 8 给定 QObject 没有 objectName () set.
QRemoteObjectNode::HostUrlInvalid 9 The given url has an invalid or unrecognized scheme.
QRemoteObjectNode::ProtocolMismatch 10 The client and the server have different protocol versions.
QRemoteObjectNode::ListenFailed 11 Can't listen on the specified host port.

[since 5.12] QRemoteObjectNode:: RemoteObjectSchemaHandler

Typedef for a std::function method that can take a QUrl input and is responsible for creating the communications channel between this node and the node hosting the desired . As some types of QIODevices (e.g., QSslSocket ) require additional steps before the device is ready for use, the method is responsible for calling addClientSideConnection once the connection is fully established.

该 typedef 在 Qt 5.12 引入。

特性文档编制

heartbeatInterval : int

心跳间隔 (以毫秒为单位)。

The heartbeat (only helpful for socket connections) will periodically send a message to connected nodes to detect whether the connection was disrupted. Qt Remote Objects will try to reconnect automatically if it detects a dropped connection. This function can help with that detection since the client will only detect that the server is unavailable when it tries to send data.

0 (默认) 将禁用心跳。

访问函数:

int heartbeatInterval () const
void setHeartbeatInterval (int interval )

通知程序信号:

void heartbeatIntervalChanged (int heartbeatInterval )

[since 5.11] persistedStore : QRemoteObjectAbstractPersistedStore *

允许设置 QRemoteObjectAbstractPersistedStore 实例为节点。

允许复本 PROP members with the PERSISTED trait to save their current value when the replica is deleted and restore a stored value the next time the replica is started.

要求 QRemoteObjectAbstractPersistedStore class implementation to control where and how persistence is handled.

该特性在 Qt 5.11 引入。

访问函数:

QRemoteObjectAbstractPersistedStore * persistedStore () const
void setPersistedStore (QRemoteObjectAbstractPersistedStore * persistedStore )

registryUrl : QUrl

This property holds the address of the 注册 used by this node.

这是空 QUrl 若没有在使用中的注册。

访问函数:

QUrl registryUrl () const
virtual bool setRegistryUrl (const QUrl & registryAddress )

成员函数文档编制

QRemoteObjectNode:: QRemoteObjectNode (const QUrl & registryAddress , QObject * parent = nullptr)

QRemoteObjectNode connected to a { QRemoteObjectRegistry } {Registry}. A Node constructed in this manner can not be connected to, and thus can not expose Source objects on the network. Finding and connecting to other (Host) Nodes is handled by the QRemoteObjectRegistry 指定通过 registryAddress .

另请参阅 connectToNode , setRegistryUrl , QRemoteObjectHost ,和 QRemoteObjectRegistryHost .

QRemoteObjectNode:: QRemoteObjectNode ( QObject * parent = nullptr)

Default constructor for QRemoteObjectNode with the given parent . A Node constructed in this manner can not be connected to, and thus can not expose Source objects on the network. It also will not include a QRemoteObjectRegistry , unless set manually using setRegistryUrl .

另请参阅 connectToNode and setRegistryUrl .

[signal] void QRemoteObjectNode:: remoteObjectAdded (const QRemoteObjectSourceLocation & loc )

This signal is emitted whenever a new object is added to the Registry. The signal will not be emitted if there is no Registry set (i.e., Sources over connections made via connectToNode directly). The loc parameter contains the information about the added Source, including name, type and the QUrl of the hosting Node.

另请参阅 remoteObjectRemoved () 和 instances ().

[signal] void QRemoteObjectNode:: remoteObjectRemoved (const QRemoteObjectSourceLocation & loc )

This signal is emitted whenever a known object is removed from the Registry. The signal will not be emitted if there is no Registry set (i.e., Sources over connections made via connectToNode directly). The loc parameter contains the information about the removed Source, including name, type and the QUrl of the hosting Node.

另请参阅 remoteObjectAdded and instances .

template <typename ObjectType> ObjectType *QRemoteObjectNode:: acquire (const QString & name = QString())

Returns a pointer to a Replica of type ObjectType (which is a template parameter and must inherit from QRemoteObjectReplica ). That is, the template parameter must be a repc generated type. The name parameter can be used to specify the name given to the object during the QRemoteObjectHost::enableRemoting () 调用。

QRemoteObjectDynamicReplica *QRemoteObjectNode:: acquireDynamic (const QString & name )

返回 QRemoteObjectDynamicReplica of the Source name .

QAbstractItemModelReplica *QRemoteObjectNode:: acquireModel (const QString & name , QtRemoteObjects::InitialAction action = QtRemoteObjects::FetchRootSize, const QList < int > & rolesHint = {})

返回指针指向 复本 which is specifically derived from QAbstractItemModel name provided must match the name used with the matching enableRemoting that put the Model on the network. action specifies whether the model should fetch data before the initialized signal is emitted. If it's set to QtRemoteObjects::PrefetchData , then the data for roles in the rolesHint will be prefetched. If rolesHint is empty, then the data for all the roles exposed by will be prefetched.

The returned model will be empty until it is initialized with the .

[since 5.12] void QRemoteObjectNode:: addClientSideConnection ( QIODevice * ioDevice )

In order to QRemoteObjectNode::acquire () 复本 objects over 外部 QIODevices , Qt Remote Objects needs access to the communications channel (a QIODevice ) between the respective nodes. It is the addClientSideConnection() call that enables this, taking the ioDevice as input. Any acquire () call made without calling addClientSideConnection will still work, but the Node will not be able to initialize the 复本 without being provided the connection to the Host node.

该函数在 Qt 5.12 引入。

另请参阅 QRemoteObjectHostBase::addHostSideConnection .

[invokable] bool QRemoteObjectNode:: connectToNode (const QUrl & address )

将客户端节点连接到主机节点按 address .

连接将仍然有效,直到主机节点被删除 (或通过网络不再可访问)。

客户端一旦连接到主机,然后就可以获得有效 Replica (复本) 若正远程相应 Source (源)。

返回 true 当成功时, false 否则 (通常是无法识别的 URL,或连接到已连接地址)。

注意: 此函数可以被援引,通过元对象系统和从 QML。见 Q_INVOKABLE .

template <typename T> QStringList QRemoteObjectNode:: instances () const

This templated function (taking a repc generated type as the template parameter) will return the list of names of every instance of that type on the Remote Objects network. For example, if you have a Shape class defined in a .rep file, and Circle and Square classes inherit from the Source definition, they can be shared on the Remote Objects network using enableRemoting .

Square square;
Circle circle;
myHost.enableRemoting(&square, "Square");
myHost.enableRemoting(&circle, "Circle");
					

Then instance can be used to find the available instances of Shape.

QStringList instances = clientNode.instances<Shape>();
// will return a QStringList containing "Circle" and "Square"
auto instance1 = clientNode.acquire<Shape>("Circle");
auto instance2 = clientNode.acquire<Shape>("Square");
...
					

QStringList QRemoteObjectNode:: instances ( QStringView typeName ) const

此函数重载 instances()。

This convenience function provides the same result as the templated version, but takes the name of the 类作为参数 ( typeName ) rather than deriving it from the class type.

QRemoteObjectNode::ErrorCode QRemoteObjectNode:: lastError () const

返回最后错误集。

[since 5.12] void QRemoteObjectNode:: registerExternalSchema (const QString & schema , QRemoteObjectNode::RemoteObjectSchemaHandler handler )

提供自定义方法以处理外部提供模式

此方法会被捆绑到 注册 and 外部模式 . By registering a std::function handler for an external schema, the registered method will be called when the registry is notified of a you've acquired being available. Without this registration, QtRO would only be able to handle the "built-in" schemas.

提供的方法 handler , will be called when the registry sees a object on a new (not yet connected) Node with a {QUrl::schema()} of schema handler , of type QRemoteObjectNode::RemoteObjectSchemaHandler will get the QUrl of the Node providing the as an input parameter, and is responsible for establishing the communications channel (a QIODevice of some sort) and calling addClientSideConnection with it.

该函数在 Qt 5.12 引入。

另请参阅 RemoteObjectSchemaHandler .

const QRemoteObjectRegistry *QRemoteObjectNode:: registry () const

返回指针指向节点的 QRemoteObjectRegistry , if the Node is using the Registry feature; otherwise it returns nullptr .

[虚拟] void QRemoteObjectNode:: setName (const QString & name )

设置 name as the internal name for this Node. This is then output as part of the logging (if enabled). This is primarily useful if you merge log data from multiple nodes.

[override virtual protected] void QRemoteObjectNode:: timerEvent ( QTimerEvent *)

重实现: QObject::timerEvent (QTimerEvent *event).

bool QRemoteObjectNode:: waitForRegistry ( int timeout = 30000)

阻塞直到此节点的 注册 被初始化或 timeout (以毫秒为单位) 过期。返回 true 注册 被成功初始化当返回时,或 false 否则。