A node on a Qt Remote Objects network. More...
Header: | #include <QRemoteObjectNode> |
qmake: | QT += remoteobjects |
Inherits: | QObject |
Inherited By: |
enum | ErrorCode { NoError, RegistryNotAcquired, RegistryAlreadyHosted, NodeIsNoServer, ..., ProtocolMismatch } |
QRemoteObjectNode(QObject *parent = nullptr) | |
QRemoteObjectNode(const QUrl ®istryAddress, 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, const QVector<int> &rolesHint) |
bool | connectToNode(const QUrl &address) |
int | heartbeatInterval() const |
QStringList | instances() const |
QStringList | instances(const QString &typeName) const |
QRemoteObjectNode::ErrorCode | lastError() const |
QRemoteObjectAbstractPersistedStore * | persistedStore() const |
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 ®istryAddress) |
bool | waitForRegistry(int timeout = 30000) |
void | error(QRemoteObjectNode::ErrorCode errorCode) |
void | heartbeatIntervalChanged(int heartbeatInterval) |
void | remoteObjectAdded(const QRemoteObjectSourceLocation &loc) |
void | remoteObjectRemoved(const QRemoteObjectSourceLocation &) |
QRemoteObjectNode(QRemoteObjectNodePrivate &, QObject *parent) |
virtual void | timerEvent(QTimerEvent *) override |
A node on a Qt Remote Objects network.
The QRemoteObjectNode class provides an entry point to a QtRemoteObjects network. A network can be as simple as two nodes, or an arbitrarily complex set of processes and devices.
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 Nodes can share).
Nodes may connect to each other directly using connectToNode, or they can use the QRemoteObjectRegistry to simplify connections.
The QRemoteObjectRegistry is a special replica available to every node that connects to the Registry Url. It knows how to connect to every QRemoteObjectSource object on the network.
See also QRemoteObjectHost and QRemoteObjectRegistryHost.
This enum type specifies the various error codes associated with QRemoteObjectNode errors:
Constant | Value | Description |
---|---|---|
QRemoteObjectNode::NoError |
0 |
No error. |
QRemoteObjectNode::RegistryNotAcquired |
1 |
The registry could not be acquired. |
QRemoteObjectNode::RegistryAlreadyHosted |
2 |
The registry is already defined and hosting Sources. |
QRemoteObjectNode::NodeIsNoServer |
3 |
The given QRemoteObjectNode is not a host node. |
QRemoteObjectNode::ServerAlreadyCreated |
4 |
The host node has already been initialized. |
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 |
The given QObject does not have 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. |
Heartbeat interval in ms.
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 the server is unavailable when it tries to send data.
Setting to 0 (the default) will disable the heartbeat.
Access functions:
int | heartbeatInterval() const |
void | setHeartbeatInterval(int interval) |
Notifier signal:
void | heartbeatIntervalChanged(int heartbeatInterval) |
Allows setting a QRemoteObjectAbstractPersistedStore instance for the node
Allows replica 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.
Requires a QRemoteObjectAbstractPersistedStore class implementation to control where and how persistence is handled.
This property was introduced in Qt 5.11.
Access functions:
QRemoteObjectAbstractPersistedStore * | persistedStore() const |
void | setPersistedStore(QRemoteObjectAbstractPersistedStore *persistedStore) |
This property holds the address of the Registry used by this node.
This will be an empty QUrl if there is no registry in use.
Access functions:
QUrl | registryUrl() const |
virtual bool | setRegistryUrl(const QUrl ®istryAddress) |
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.
See also connectToNode and setRegistryUrl.
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 specified by registryAddress.
See also connectToNode, setRegistryUrl, QRemoteObjectHost, and 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.
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() call.
Returns a QRemoteObjectDynamicReplica of the Source name.
Returns a pointer to a Replica which is specifically derived from QAbstractItemModel. The 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.
Connects a client node to the host node at address.
Connections will remain valid until the host node is deleted or no longer accessible over a network.
Once a client is connected to a host, valid Replicas can then be acquired if the corresponding Source is being remoted.
Return true
on success, false
otherwise (usually an unrecognized url, or connecting to already connected address).
Note: This function can be invoked via the meta-object system and from QML. See Q_INVOKABLE.
[signal]
void QRemoteObjectNode::error(QRemoteObjectNode::ErrorCode
errorCode)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"); ...
This function overloads instances().
This convenience function provides the same result as the templated version, but takes the name of the Source class as a parameter (typeName) rather than deriving it from the class type.
Returns the last error set.
Returns a pointer to the Node's QRemoteObjectRegistry, if the Node is using the Registry feature; otherwise it returns 0.
[signal]
void QRemoteObjectNode::remoteObjectAdded(const QRemoteObjectSourceLocation &loc)This signal is emitted whenever a new 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.
See also remoteObjectRemoved and instances.
[signal]
void QRemoteObjectNode::remoteObjectRemoved(const
QRemoteObjectSourceLocation &)[virtual]
void QRemoteObjectNode::setName(const QString &name)Sets 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 *)Reimplemented from QObject::timerEvent().
Blocks until this Node's Registry is initialized or timeout (in milliseconds) expires. Returns true
if the Registry is successfully initialized upon return, or false
otherwise.