QWebChannel Class
Exposes QObjects to remote HTML clients. More...
Header: | #include <QWebChannel> |
qmake: | QT += webchannel |
Since: | Qt 5.4 |
Inherits: | QObject |
Properties
- blockUpdates : bool
- 1 property inherited from QObject
Public Functions
QWebChannel(QObject *parent = Q_NULLPTR) | |
virtual | ~QWebChannel() |
bool | blockUpdates() const |
void | deregisterObject(QObject *object) |
void | registerObject(const QString &id, QObject *object) |
void | registerObjects(const QHash<QString, QObject *> &objects) |
QHash<QString, QObject *> | registeredObjects() const |
void | setBlockUpdates(bool block) |
- 31 public functions inherited from QObject
Public Slots
void | connectTo(QWebChannelAbstractTransport *transport) |
void | disconnectFrom(QWebChannelAbstractTransport *transport) |
- 1 public slot inherited from QObject
Signals
void | blockUpdatesChanged(bool block) |
- 2 signals inherited from QObject
Static Public Members
const QMetaObject | staticMetaObject |
- 9 static public members inherited from QObject
Additional Inherited Members
- 9 protected functions inherited from QObject
Detailed Description
Exposes QObjects to remote HTML clients.
The QWebChannel fills the gap between C++ applications and HTML/JavaScript applications. By publishing a QObject derived object to a QWebChannel and using the qwebchannel.js on the HTML side, one can transparently access properties and public slots and methods of the QObject. No manual message passing and serialization of data is required, property updates and signal emission on the C++ side get automatically transmitted to the potentially remotely running HTML clients. On the client side, a JavaScript object will be created for any published C++ QObject. It mirrors the C++ object's API and thus is intuitively useable.
The C++ QWebChannel API makes it possible to talk to any HTML client, which could run on a local or even remote machine. The only limitation is that the HTML client supports the JavaScript features used by qwebchannel.js
. As such, one can interact with basically any modern HTML browser or standalone JavaScript runtime, such as node.js.
There also exists a declarative WebChannel API.
See also Qt WebChannel Standalone Example and JavaScript API.
Property Documentation
blockUpdates : bool
When set to true, updates are blocked and remote clients will not be notified about property changes.
The changes are recorded and sent to the clients once updates become unblocked again by setting this property to false. By default, updates are not blocked.
Access functions:
bool | blockUpdates() const |
void | setBlockUpdates(bool block) |
Notifier signal:
void | blockUpdatesChanged(bool block) |
Member Function Documentation
QWebChannel::QWebChannel(QObject *parent = Q_NULLPTR)
Constructs the QWebChannel object with the given parent.
Note that a QWebChannel is only fully operational once you connect it to a QWebChannelAbstractTransport. The HTML clients also need to be setup appropriately using qwebchannel.js
.
[virtual]
QWebChannel::~QWebChannel()
Destroys the QWebChannel.
[slot]
void QWebChannel::connectTo(QWebChannelAbstractTransport *transport)
Connects the QWebChannel to the given transport object.
The transport object then handles the communication between the C++ application and a remote HTML client.
See also QWebChannelAbstractTransport and QWebChannel::disconnectFrom().
void QWebChannel::deregisterObject(QObject *object)
Deregisters the given object from the QWebChannel.
Remote clients will receive a destroyed
signal for the given object.
Note: This function can be invoked via the meta-object system and from QML. See Q_INVOKABLE.
See also QWebChannel::registerObjects(), QWebChannel::registerObject(), and QWebChannel::registeredObjects().
[slot]
void QWebChannel::disconnectFrom(QWebChannelAbstractTransport *transport)
Disconnects the QWebChannel from the transport object.
See also QWebChannel::connectTo().
void QWebChannel::registerObject(const QString &id, QObject *object)
Registers a single object to the QWebChannel.
The properties, signals and public methods of the object are published to the remote clients. There, an object with the identifier id is then constructed.
Note: A current limitation is that objects must be registered before any client is initialized.
Note: This function can be invoked via the meta-object system and from QML. See Q_INVOKABLE.
See also QWebChannel::registerObjects(), QWebChannel::deregisterObject(), and QWebChannel::registeredObjects().
void QWebChannel::registerObjects(const QHash<QString, QObject *> &objects)
Registers a group of objects to the QWebChannel.
The properties, signals and public invokable methods of the objects are published to the remote clients. There, an object with the identifier used as key in the objects map is then constructed.
Note: A current limitation is that objects must be registered before any client is initialized.
See also QWebChannel::registerObject(), QWebChannel::deregisterObject(), and QWebChannel::registeredObjects().
QHash<QString, QObject *> QWebChannel::registeredObjects() const
Returns the map of registered objects that are published to remote clients.
See also QWebChannel::registerObjects(), QWebChannel::registerObject(), and QWebChannel::deregisterObject().
© 2019 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.