QRemoteObjectHostBase 類

QRemoteObjectHostBase 類提供基本共有功能為 Host and RegistryHost 類。 更多...

頭: #include <QRemoteObjectHostBase>
qmake: QT += remoteobjects
繼承: QRemoteObjectNode
繼承者:

QRemoteObjectHost and QRemoteObjectRegistryHost

公共類型

enum AllowedSchemas { BuiltInSchemasOnly, AllowExternalRegistration }

公共函數

void addHostSideConnection (QIODevice * ioDevice )
bool disableRemoting (QObject * remoteObject )
bool enableRemoting (ObjectType * object )
bool enableRemoting (QObject * object , const QString & name = QString())
bool enableRemoting (QAbstractItemModel * model , const QString & name , const QVector<int> roles , QItemSelectionModel * selectionModel = nullptr)
bool proxy (const QUrl & registryUrl , const QUrl & hostUrl = {}, QRemoteObjectHostBase::RemoteObjectNameFilter filter = [](const QString &, const QString &) {return true; })
bool reverseProxy (QRemoteObjectHostBase::RemoteObjectNameFilter filter = [](const QString &, const QString &) {return true; })

重實現公共函數

virtual void setName (const QString & name ) override

詳細描述

QRemoteObjectHostBase 是無法直接實例化的基類。它提供 enableRemoting and disableRemoting 功能由所有主機節點共享 ( Host and RegistryHost ) 及邏輯要求暴露 Source 對象在遠程對象網絡。

成員類型文檔編製

enum QRemoteObjectHostBase:: AllowedSchemas

This enum is used to specify whether a Node will accept a url with an unrecognized schema for the hostUrl. By default only urls with known schemas are accepted, but using AllowExternalRegistration will enable the 注冊 to pass your external (to QtRO) url to client Nodes.

常量 描述
QRemoteObjectHostBase::BuiltInSchemasOnly 0 Only allow the hostUrl to be set to a QtRO supported schema. This is the default value, and causes a Node error to be set if an unrecognized schema is provided.
QRemoteObjectHostBase::AllowExternalRegistration 1 The provided schema is registered as an 外部模式

另請參閱 QRemoteObjectHost .

成員函數文檔編製

void QRemoteObjectHostBase:: addHostSideConnection ( QIODevice * ioDevice )

QRemoteObjectHost::enableRemoting () Source 對象通過 外部 QIODevices ,Qt Remote Objects 需要訪問通信通道 ( QIODevice ) between the respective nodes. It is the addHostSideConnection() call that enables this on the Source side, taking the ioDevice as input. Any enableRemoting () call will still work without calling addHostSideConnection, but the Node will not be able to share the Source objects without being provided the connection to the Replica node. Before calling this function you must call setHostUrl () with a unique URL and AllowExternalRegistration .

該函數在 Qt 5.12 引入。

另請參閱 addClientSideConnection .

bool QRemoteObjectHostBase:: disableRemoting ( QObject * remoteObject )

禁用遠程訪問 QObject remoteObject 。返迴 false 若當前節點是客戶端節點,或者若 remoteObject 未注冊,和返迴 true 若 Source (源) 對象成功禁用遠程。

警告: 此對象的復本將不再有效,在調用此方法後。

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

另請參閱 enableRemoting ().

template <template <typename> class ApiDefinition, typename ObjectType> bool QRemoteObjectHostBase:: enableRemoting ( ObjectType * object )

此模闆化函數重載使主機節點,能夠提供遠程訪問對 QObject object 采用指定 (和編譯時校驗) 接口。連接到托管此對象的節點的客戶端節點,可以獲得此 Source (源) 的 Replica (復本)。

闡明這的最佳範例:

#include "rep_TimeModel_source.h"
MinuteTimer timer;
hostNode.enableRemoting<MinuteTimerSourceAPI>(&timer);
					

Here the MinuteTimerSourceAPI is the set of Signals/Slots/Properties defined by the TimeModel.rep file. Compile time checks are made to verify the input QObject can expose the requested API, it will fail to compile otherwise. This allows a subset of object 's interface to be exposed, and allows the types of conversions supported by Signal/Slot connections.

返迴 false 若當前節點是客戶端節點,或者若 QObject 已注冊為遠程,和 true 若成功啓用遠程為 QObject .

另請參閱 disableRemoting ().

bool QRemoteObjectHostBase:: enableRemoting ( QObject * object , const QString & name = QString())

使主機節點能夠動態提供遠程訪問 QObject object 。連接到托管此對象的節點的客戶端節點,可以獲得此源的復本。

可選 name defines the lookup-name under which the QObject can be acquired using QRemoteObjectNode::acquire () . If not explicitly set then the name given in the QCLASSINFO_REMOTEOBJECT_TYPE will be used. If no such macro was defined for the QObject 那麼 QObject::objectName () 被使用。

返迴 false 若當前節點是客戶端節點,或者若 QObject 已注冊為遠程,和 true 若成功啓用遠程為動態 QObject .

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

另請參閱 disableRemoting ().

bool QRemoteObjectHostBase:: enableRemoting ( QAbstractItemModel * model , const QString & name , const QVector < int > roles , QItemSelectionModel * selectionModel = nullptr)

This overload of enableRemoting() is specific to QAbstractItemModel types (or any type derived from QAbstractItemModel ). This is useful if you want to have a model and the HMI for the model in different processes.

The three required parameters are the model itself, the name by which to lookup the model, and the roles that should be exposed on the Replica side. If you want to synchronize selection between Source and 復本 , the optional selectionModel parameter can be used. This is only recommended when using a single Replica.

Behind the scenes, Qt Remote Objects batches data() lookups and prefetches data when possible to make the model interaction as responsive as possible.

返迴 false 若當前節點是客戶端節點,或者若 QObject 已注冊為遠程,和 true 若成功啓用遠程為 QAbstractItemModel .

另請參閱 disableRemoting ().

bool QRemoteObjectHostBase:: proxy (const QUrl & registryUrl , const QUrl & hostUrl = {}, QRemoteObjectHostBase::RemoteObjectNameFilter filter = [](const QString &, const QString &) {return true; })

從另一網絡轉發遠程對象

The proxy functionality is useful when you want to share Source objects over multiple networks. For instance, if you have an embedded target using target-only connections (like local) and you want to make some of those same objects available externally.

As a concrete example, say you have a set of processes talking to each other on your target hardware using a registry, with the 注冊 at "local:registry" and separate processes using a node at "local:MyHost" that holds Source objects. If you wanted to access these objects, but over tcp, you could create a new proxyNode like so:

// myInternalHost is a node only visible on the device...
QRemoteObjectHost myInternalHost("local:MyHost");
myInternalHost.enableRemoting<SomeObject>(&someObject);
// Regular host node, listening on port 12123, so visible to other
// devices
QRemoteObjectHost proxyNode("tcp://localhost:12123");
// Enable proxying objects from nodes on the local machine's internal
// QtRO bus
proxyNode.proxy("local:registry");
					

And from another device you create another node:

// NB: localhost resolves to a different ip address than proxyNode
QRemoteObjectHost nodeOnRemoteDevice("tcp://localhost:23234");
// Connect to the target's proxyNode directly, or use a tcp registry...
nodeOnRemoteDevice.connectToNode("tcp://<target device>:12123");
// Because of the proxy, we can get the object over tcp/ip port 12123,
// even though we can't connect directly to "local:MyHost"
SomeObject *so = nodeOnRemoteDevice.acquire<SomeObject>();
					

This would (internally) create a node in proxyNode, which (again internally/automatically) connects to the provided registry (given by the registryUrl parameter, "local:registry" in this example). Whenever local:registry emits the remoteObjectAdded signal, the QRemoteObjectSourceLocation 被傳遞給 filter given to the proxy call. If this method returns true (the default filter simply returns true without any filtering), the object is acquired() from the internal node and enableRemoting () (once the replica is initialized) is called on proxyNode.

hostUrl is provided (which is required to enable reverseProxy , but not needed otherwise), the internal node will be a QRemoteObjectHost node configured with the provided address. If no hostUrl is provided, the internal node will be a QRemoteObjectNode (not HostNode).

返迴 true if the object is acquired from the internal node.

該函數在 Qt 5.11 引入。

另請參閱 reverseProxy ().

bool QRemoteObjectHostBase:: reverseProxy ( QRemoteObjectHostBase::RemoteObjectNameFilter filter = [](const QString &, const QString &) {return true; })

轉發遠程對象到另一網絡。

The reverseProxy() function allows the proxy () functionality to be extended, in effect mirroring the proxy functionality in the "reverse" direction. These are distinct, because node communication is not symmetric, one side calls enableRemoting () 采用 Source object, the other side calls acquire () to get a 復本 。使用 proxy () allows you to "observe" objects on a target device remotely via acquire, but it does not allow off-target Source objects to be acquired from the device's local:* network. That is where reverseProxy() comes in. If a proxyNode is created like so:

// myInternalHost is a node only visible on the device...
QRemoteObjectHost myInternalHost("local:MyHost");
// RegistryHost node, listening on port 12123, so visible to other
// devices.  The node must be a RegistryHost, so the Sources on
// the "outside" network can be forwarded to the inner network.
QRemoteObjectRegistryHost proxyNode("tcp://localhost:12123");
// Enable proxying objects from nodes on the local machine's internal
// QtRO bus.  Note the hostUrl parameter is now needed.
proxyNode.proxy("local:registry", "local:fromProxy");
proxyNode.reverseProxy();
					

And from another device you create another node:

// NB: localhost resolves to a different ip address than proxyNode
QRemoteObjectHost nodeOnRemoteDevice("tcp://localhost:23234");
// Connect to the target's proxyNode directly, or use a tcp registry...
nodeOnRemoteDevice.connectToNode("tcp://<target device>:12123");
// Because of the reverseProxy, we can expose objects on this device
// and they will make their way to proxyNode...
nodeOnRemoteDevice.enableRemoting<OtherObject>(&otherObject);
					
// Acquire() can now see the objects on other devices through proxyNode,
// due to the reverseProxy call.
OtherObject *oo = myInternalHost.acquire<OtherObject>();
					

While the proxy () functionality allows Source objects on another network to be acquired(), reverseProxy() allows Source objects to be "pushed" to an otherwise inaccessible network.

注意: proxy () needs to be called before reverseProxy(), and a hostUrl needs to be provided to proxy for reverseProxy() to work. The reverseProxy() method allows a separate filter to be applied. This reverseProxy specific filter will receive notifications of new Source objects on proxyNode and acquire them on the internal node if they pass the reverseFilter.

返迴 true 當成功時, false 否則。

該函數在 Qt 5.11 引入。

另請參閱 proxy ().

[override virtual] void QRemoteObjectHostBase:: setName (const QString & name )

重實現: QRemoteObjectNode::setName (const QString &name).

類似於 QObject::setObjectName () (which this method calls), but this version also applies the name to internal classes as well, which are used in some of the debugging output.