Qt for HarmonyOS/qtohosextras doc/QOhosDistributedDataObject Class
QOhosDistributedDataObject Class
class QtOhosExtras::QOhosDistributedDataObject
The QOhosDistributedDataObject class shares a fixed set of named fields across devices that belong to the same trusted network. More...
| Header: | #include <QOhosDistributedDataObject> |
| qmake: | QT += ohosextras |
| Since: | Qt 5.12.12 |
| Inherits: | QObject |
This class was introduced in Qt 5.12.12.
Public Types
| enum class | Status { Online, Offline, Restored } |
Public Functions
| virtual void | addAssets(const QList<QSharedPointer<QFile>> &files) = 0 |
| virtual bool | areAssetsSynced() const = 0 |
| virtual QString | assetKey() const = 0 |
| virtual QJsonArray | assets() const = 0 |
| virtual QStringList | fieldNames() const = 0 |
| virtual QJsonValue | get(const QString &key) const = 0 |
| virtual void | save(const QString &deviceId) = 0 |
| virtual QString | sessionId() const = 0 |
Signals
| void | dataChanged(QString sessionId, QStringList changedFields) |
| void | progressChanged(QString sessionId, int progress) |
| void | saveFinished(bool success) |
| void | statusChanged(QString sessionId, QString networkId, QtOhosExtras::QOhosDistributedDataObject::Status status) |
Static Public Members
| QSharedPointer<QOhosDistributedDataObject> | create(const QJsonObject &source) |
Detailed Description
An object wraps the fields it was created with (see create()). Once objects on different devices join the same distributed session, the system keeps their fields in sync: values set locally are propagated to the peers, and remote changes are reported through dataChanged().
In addition to its fields, an object can carry file assets: files attached with addAssets() are copied into the distributed files directory right away and transferred alongside the fields.
See also create() and tryRestoreOnContinueDistributedDataObjects().
Member Type Documentation
enum class QOhosDistributedDataObject::Status
Describes the synchronization status of the object as reported by statusChanged().
| Constant | Value | Description |
|---|---|---|
QtOhosExtras::QOhosDistributedDataObject::Status::Online
|
0
|
The object is connected to a peer device and syncing. |
QtOhosExtras::QOhosDistributedDataObject::Status::Offline
|
1
|
The object is not connected to any peer device. |
QtOhosExtras::QOhosDistributedDataObject::Status::Restored
|
2
|
The object's data has been restored from a peer device. |
Member Function Documentation
[signal] void QOhosDistributedDataObject::dataChanged(QString sessionId, QStringList changedFields)
Signal emitted when fields change as a result of a remote update on the session identified by sessionId. changedFields lists the names of the fields that changed; their new values can be read with get().
[signal] void QOhosDistributedDataObject::progressChanged(QString sessionId, int progress)
Signal emitted while the object is being synchronized on the session identified by sessionId, reporting the synchronization progress as a percentage in the range 0 to 100.
[signal] void QOhosDistributedDataObject::saveFinished(bool success)
Signal emitted when a save() operation finishes. success is true if the object was persisted successfully, false otherwise.
See also save().
[signal] void QOhosDistributedDataObject::statusChanged(QString sessionId, QString networkId, QtOhosExtras::QOhosDistributedDataObject::Status status)
Signal emitted when the synchronization status of the object becomes status on the session identified by sessionId. networkId identifies the peer device the status refers to.
Attaches files to the object as distributed file assets. An object cannot carry file contents in its fields, so each file is copied into the distributed files directory right away and only the resulting paths travel with the object.
Assets have to be attached before the object joins a distributed session, that is before it is saved with save() or restored with tryRestoreOnContinueDistributedDataObjects(). Attaching them later has no effect.
See also assets() and areAssetsSynced().
[pure virtual] bool QOhosDistributedDataObject::areAssetsSynced() const
Returns true if every asset added with addAssets() has been copied into the distributed files directory and registered with the object, or if the object has no assets.
See also addAssets().
[pure virtual] QString QOhosDistributedDataObject::assetKey() const
Returns the name of the field under which the object's asset paths are stored, or an empty string if no assets were added with addAssets().
See also addAssets() and assets().
[pure virtual] QJsonArray QOhosDistributedDataObject::assets() const
Returns the object's assets as reported by the platform, one JSON object per asset with the fields the system defines for an asset, like "name", "uri" and "path". The array is empty until every asset added with addAssets() has been copied. See Asset
See also addAssets() and assetKey().
Creates a distributed data object holding the fields given in source and returns it. The set of field names is fixed at creation time.
See also get() and fieldNames().
[pure virtual] QStringList QOhosDistributedDataObject::fieldNames() const
Returns the names of all fields held by the object.
[pure virtual] QJsonValue QOhosDistributedDataObject::get(const QString &key) const
Returns the current value of the field named key, or a null QJsonValue if the object has no such field.
[pure virtual] void QOhosDistributedDataObject::save(const QString &deviceId)
Persists the object to the device identified by deviceId so its data survives the peer going offline. If the object has not joined a distributed session yet, one is created for it and can be read afterwards with sessionId(). Completion is reported through saveFinished().
See also saveFinished() and sessionId().
[pure virtual] QString QOhosDistributedDataObject::sessionId() const
Returns the id of the distributed session the object belongs to, or an empty string if it has not joined one yet.