QRemoteObjectNode 類

Qt Remote Objects 網絡節點。 更多...

頭: #include <QRemoteObjectNode>
qmake: QT += remoteobjects
實例化: Node
繼承: QObject
繼承者: QRemoteObjectHostBase

公共類型

enum ErrorCode { NoError, RegistryNotAcquired, RegistryAlreadyHosted, NodeIsNoServer, ..., ListenFailed }
typedef RemoteObjectSchemaHandler

特性

公共函數

QRemoteObjectNode (QObject * parent = nullptr)
QRemoteObjectNode (const QUrl & registryAddress , QObject * parent = nullptr)
virtual ~QRemoteObjectNode () override
ObjectType * acquire (const QString & name = QString())
QRemoteObjectDynamicReplica * acquireDynamic (const QString & name )
QAbstractItemModelReplica * acquireModel (const QString & name , QtRemoteObjects::InitialAction action = QtRemoteObjects::FetchRootSize, const QVector<int> & rolesHint = {})
void addClientSideConnection (QIODevice * ioDevice )
bool connectToNode (const QUrl & address )
int heartbeatInterval () const
QStringList instances () const
QStringList instances (const QString & 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 error (QRemoteObjectNode::ErrorCode errorCode )
void heartbeatIntervalChanged (int heartbeatInterval )
void remoteObjectAdded (const QRemoteObjectSourceLocation & loc )
void remoteObjectRemoved ( const QRemoteObjectSourceLocation & )

靜態公共成員

const QMetaObject staticMetaObject

保護函數

QRemoteObjectNode ( QRemoteObjectNodePrivate & , QObject * parent )

重實現保護函數

virtual void timerEvent ( QTimerEvent * ) override

額外繼承成員

詳細描述

Qt Remote Objects 網絡節點。

The QRemoteObjectNode class provides an entry point to a QtRemoteObjects 網絡。網絡可以如 2 節點般簡單 (或任意復雜的一組進程和設備)。

A QRemoteObjectNode does not have a url that other nodes can connect to, and thus is able to acquire replicas only. It is not able to share source objects (only QRemoteObjectHost and QRemoteObjectRegistryHost 節點可以共享)。

節點可以相互直接連接使用 connectToNode ,或者它們可以使用 QRemoteObjectRegistry 以簡化連接。

The 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 試圖創建主機 QRemoteObjectNode 並連接到自身因注冊。
QRemoteObjectNode::OperationNotValidOnClientNode 6 嘗試的操作無效在客戶端 QRemoteObjectNode .
QRemoteObjectNode::SourceNotRegistered 7 給定的 QRemoteObjectSource 在此節點未注冊。
QRemoteObjectNode::MissingObjectName 8 給定 QObject 沒有 objectName () set.
QRemoteObjectNode::HostUrlInvalid 9 給定的 URL 擁有無效 (或無法識彆) 的模式。
QRemoteObjectNode::ProtocolMismatch 10 客戶端和服務器,擁有不同協議版本。
QRemoteObjectNode::ListenFailed 11 無法監聽指定主機端口。

typedef QRemoteObjectNode:: RemoteObjectSchemaHandler

typedef 對於 std::function 方法可以接受 QUrl input and is responsible for creating the communications channel between this node and the node hosting the desired Source . 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 )

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

此特性保持地址為 注冊 用於此節點。

這是空 QUrl 若使用中沒有注冊。

訪問函數:

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

成員函數文檔編製

QRemoteObjectNode:: QRemoteObjectNode ( QObject * parent = nullptr)

Default constructor for QRemoteObjectNode 采用給定 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 .

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 .

[protected] QRemoteObjectNode:: QRemoteObjectNode ( QRemoteObjectNodePrivate & , QObject * parent )

Default constructs an instance of QRemoteObjectNode.

[override virtual] QRemoteObjectNode:: ~QRemoteObjectNode ()

Destroys the instance of QRemoteObjectNode. The destructor is virtual.

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 QVector < int > & rolesHint = {})

Returns a pointer to a Replica which is specifically derived from QAbstractItemModel name provided must match the name used with the matching enableRemoting that put the Model on the network. The returned model will be empty until it is initialized with the Source .

void QRemoteObjectNode:: addClientSideConnection ( QIODevice * ioDevice )

QRemoteObjectNode::acquire () 復本 對象通過 外部 QIODevices ,Qt Remote Objects 需要訪問通信通道 ( 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 .

bool QRemoteObjectNode:: connectToNode (const QUrl & address )

將客戶端節點連接到主機節點按 address .

連接將仍然有效,直到主機節點被刪除 (或通過網絡不再可訪問)。

客戶端一旦連接到主機,然後就可以獲得有效 Replica (復本) 若正遠程相應 Source (源)。

返迴 true 當成功時, false 否則 (通常是無法識彆的 URL,或連接到已連接地址)。

注意: 此函數可以被援引,通過元對象係統和從 QML。見 Q_INVOKABLE .

[signal] void QRemoteObjectNode:: error ( QRemoteObjectNode::ErrorCode errorCode )

QStringList QRemoteObjectNode:: instances () const

此模闆化函數 (接受 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 (const QString & typeName ) const

此函數重載 instances ().

This convenience function provides the same result as the templated version, but takes the name of the Source 類作為參數 ( typeName ) rather than deriving it from the class type.

QRemoteObjectNode::ErrorCode QRemoteObjectNode:: lastError () const

返迴最後錯誤集。

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 Source 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 Source 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 Source 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 ,若 Node 正使用 Registry 特徵;否則 , 返迴 0。

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

此信號發射,每當新的 Source 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 and instances .

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

[虛擬] 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 ().

bool QRemoteObjectNode:: waitForRegistry ( int timeout = 30000)

阻塞直到此節點的 注冊 被初始化或 timeout (以毫秒為單位) 過期。返迴 true 注冊 被成功初始化當返迴時,或 false 否則。