QWebChannel

Exposes QObjects to remote HTML clients. More

Inheritance diagram of PySide2.QtWebChannel.QWebChannel

Synopsis

Functions

Slots

Signals

Detailed Description

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 JavaScript API

class PySide2.QtWebChannel.QWebChannel([parent=Q_NULLPTR])
param parent

PySide2.QtCore.QObject

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 :ref:` <Qt-WebChannel-JavaScript-API>` .

PySide2.QtWebChannel.QWebChannel.blockUpdates()
Return type

bool

This property holds 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.

PySide2.QtWebChannel.QWebChannel.blockUpdatesChanged(block)
Parameters

block – bool

PySide2.QtWebChannel.QWebChannel.connectTo(transport)
Parameters

transportPySide2.QtWebChannel.QWebChannelAbstractTransport

Connects the QWebChannel to the given transport object.

The transport object then handles the communication between the C++ application and a remote HTML client.

PySide2.QtWebChannel.QWebChannel.deregisterObject(object)
Parameters

objectPySide2.QtCore.QObject

Deregisters the given object from the QWebChannel .

Remote clients will receive a destroyed signal for the given object.

PySide2.QtWebChannel.QWebChannel.disconnectFrom(transport)
Parameters

transportPySide2.QtWebChannel.QWebChannelAbstractTransport

Disconnects the QWebChannel from the transport object.

See also

connectTo()

PySide2.QtWebChannel.QWebChannel.registerObject(id, object)
Parameters

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.

PySide2.QtWebChannel.QWebChannel.registerObjects(objects)
Parameters

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.

PySide2.QtWebChannel.QWebChannel.registeredObjects()
Return type

Returns the map of registered objects that are published to remote clients.

PySide2.QtWebChannel.QWebChannel.setBlockUpdates(block)
Parameters

block – bool

This property holds 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.