QRemoteObjectHostBase Class

The QRemoteObjectHostBase class provides base functionality common to Host and RegistryHost classes. 更多...

头文件: #include <QRemoteObjectHostBase>
qmake: QT += remoteobjects
基类: QRemoteObjectNode
派生类:

QRemoteObjectHost and QRemoteObjectRegistryHost

公有函数

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)

重新实现的公有函数

virtual void setName(const QString &name) override

其他继承的成员

详细描述

The QRemoteObjectHostBase class provides base functionality common to Host and RegistryHost classes.

QRemoteObjectHostBase is a base class that cannot be instantiated directly. It provides the enableRemoting and disableRemoting functionality shared by all host nodes (Host and RegistryHost) as well as the logic required to expose Source objects on the Remote Objects network.

成员函数

bool QRemoteObjectHostBase::disableRemoting(QObject *remoteObject)

Disables remote access for the QObject remoteObject. Returns false if the current node is a client node or if the remoteObject is not registered, and returns true if remoting is successfully disabled for the Source object.

Warning: Replicas of this object will no longer be valid after calling this method.

参见 enableRemoting().

bool QRemoteObjectHostBase::enableRemoting(ObjectType *object)

This templated function overload enables a host node to provide remote access to a QObject object with a specified (and compile-time checked) interface. Client nodes connected to the node hosting this object may obtain Replicas of this Source.

This is best illustrated by example:


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

Returns false if the current node is a client node, or if the QObject is already registered to be remoted, and true if remoting is successfully enabled for the QObject.

参见 disableRemoting().

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

Enables a host node to dynamically provide remote access to the QObject object. Client nodes connected to the node hosting this object may obtain Replicas of this Source.

The 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 then the QObject::objectName() is used.

Returns false if the current node is a client node, or if the QObject is already registered to be remoted, and true if remoting is successfully enabled for the dynamic QObject.

参见 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 Replica, 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.

Returns false if the current node is a client node, or if the QObject is already registered to be remoted, and true if remoting is successfully enabled for the QAbstractItemModel.

参见 disableRemoting().

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

Reimplemented from QRemoteObjectNode::setName().

Similar to 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.