QRemoteObjectReplica Class | Qt Remote Objects 5.9

Qt 5.9 | Qt Remote Objects | C++ Classes | QRemoteObjectReplica

Qt 5.9.3 Reference Documentation

# QRemoteObjectReplica Class

A class interacting with (but not implementing) a Qt API on the Remote Object network More...

Header: | #include <QRemoteObjectReplica>
qmake: | QT += remoteobjects
Inherited By: | QRemoteObjectDynamicReplica and QRemoteObjectRegistry

- List of all members, including inherited members

## Public Types

enum | State { Uninitialized, Default, Valid, Suspect, SignatureMismatch }

## Properties

- node : QRemoteObjectNode *
- state : const State

## Public Functions

bool | isInitialized() const
bool | isReplicaValid() const
QRemoteObjectNode * | node() const
void | setNode(QRemoteObjectNode *node)
State | state() const
bool | waitForSource(int timeout = 30000)

## Signals

void | initialized()
void | stateChanged(State state, State oldState)

## Detailed Description

A class interacting with (but not implementing) a Qt API on the Remote Object network

A Remote Object Replica is a QObject proxy for another QObject (called the Source object). Once initialized, a replica can be considered a "latent copy" of the Source object. That is, every change to a Q_PROPERTY on the Source, or signal emitted by the Source will be updated/emitted by all Replica objects. Latency is introduced by process scheduling by any OSes involved and network communication latency. As long as the replica has been initialized and the communication is not disrupted, receipt and order of changes is guaranteed.

The isInitialized and state properties (and corresponding initialized()/stateChanged() signals) allow the state of a Replica to be determined.

While Qt Remote Objects (QtRO) handles the initialization and synchronization of Replica objects, there are numerous steps happening behind the scenes which can fail and that aren't encountered in single process Qt applications. See Troubleshooting for advice on how to handle such issues when using a remote objects network.

## Member Type Documentation

### enum QRemoteObjectReplica::State

This enum type specifies the various state codes associated with QRemoteObjectReplica states:

Constant | Value | Description
--- | --- | ---
`QRemoteObjectReplica::Uninitialized` | `0` | initial value of DynamicReplica, where nothing is known about the replica before connection to source.
`QRemoteObjectReplica::Default` | `1` | initial value of static replica, where any defaults set in the .rep file are available so it can be used if necessary.
`QRemoteObjectReplica::Valid` | `2` | indicates the replica is connected, has good property values and can be interacted with.
`QRemoteObjectReplica::Suspect` | `3` | error state that occurs if the connection to the source is lost after it is initialized.
`QRemoteObjectReplica::SignatureMismatch` | `4` | error state that occurs if a connection to the source is made, but the source and replica are not derived from the same .rep (only possible for static Replicas).

## Property Documentation

### node : QRemoteObjectNode *

This property holds a pointer to the node this object was acquired from.

Access functions:

QRemoteObjectNode * | node() const
void | setNode(QRemoteObjectNode *node)

### state : const State

Returns the replica state.

This property holds the replica QRemoteObjectReplica::State.

Access functions:

State | state() const

Notifier signal:

void | stateChanged(State state, State oldState)

## Member Function Documentation

### `[signal]` void QRemoteObjectReplica::initialized()

This signal is emitted once the replica is initialized.

See also isInitialized() and stateChanged().

### bool QRemoteObjectReplica::isInitialized() const

Returns `true` if this replica has been initialized with data from the Source object. Returns `false` otherwise.

See also state().

### bool QRemoteObjectReplica::isReplicaValid() const

Returns `true` if this replica has been initialized and has a valid connection with the node hosting the Source. Returns `false` otherwise.

See also isInitialized().

### State QRemoteObjectReplica::state() const

Returns `true` if this replica has been initialized with data from the Source object. Returns `false` otherwise.

Note: Getter function for property state.

See also isInitialized().

### `[signal]` void QRemoteObjectReplica::stateChanged(State state, State oldState)

This signal is emitted whenever a replica's state toggles between QRemoteObjectReplica::State.

The change in state is represented with state and oldState.

Note: Notifier signal for property state.

See also state() and initialized().

### bool QRemoteObjectReplica::waitForSource(int timeout = 30000)

Blocking call that waits for the replica to become initialized or until the timeout (in ms) expires. Returns `true` if the replica is initialized when the call completes, `false` otherwise.

If timeout is -1, this function will not time out.

See also isInitialized() and initialized().