- class QWebChannel¶
Exposes QObjects to remote HTML clients. More…
Synopsis¶
Properties¶
blockUpdatesᅟ
- When set to true, updates are blocked and remote clients will not be notified about property changespropertyUpdateIntervalᅟ
- Property update interval
Methods¶
def
__init__()
def
blockUpdates()
def
registerObject()
Slots¶
def
connectTo()
def
disconnectFrom()
Signals¶
Note
This documentation may contain snippets that were automatically translated from C++ to Python. We always welcome contributions to the snippet translation. If you see an issue with the translation, you can also let us know by creating a ticket on https:/bugreports.qt.io/projects/PYSIDE
Detailed Description¶
The
QWebChannel
fills the gap between C++ applications and HTML/JavaScript applications. By publishing a QObject derived object to aQWebChannel
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.QWebChannel
transparently supports QFuture. When a client calls a method that returns a QFuture,QWebChannel
will send a response with the QFuture result only after the QFuture has finished.Custom conversion of types to and from JSON is supported by defining converters with QMetaType::registerConverter() to and from QJsonValue. Note that custom converters from QJsonValue to a concrete type must fail if the QJsonValue does not match the expected format. Otherwise
QWebChannel
cannot fall back to its default conversion mechanisms. Custom converters are also available on the JavaScript side .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 byqwebchannel.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
registerConverter()
Note
Properties can be used directly when
from __feature__ import true_property
is used or via accessor functions otherwise.- property blockUpdatesᅟ: 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.- Access functions:
- property propertyUpdateIntervalᅟ: int¶
This property holds The property update interval..
This interval can be changed to a different interval in milliseconds by setting it to a positive value. Property updates are batched and sent out after the interval expires. If set to zero, the updates occurring within a single event loop run are batched and sent out on the next run. If negative, updates will be sent immediately. Default value is 50 milliseconds.
- Access functions:
Constructs the
QWebChannel
object with the givenparent
.Note that a
QWebChannel
is only fully operational once you connect it to aQWebChannelAbstractTransport
. The HTML clients also need to be setup appropriately usingqwebchannel.js
:ref:` <Qt-WebChannel-JavaScript-API>` .- blockUpdates()¶
- Return type:
bool
See also
Getter of property
blockUpdatesᅟ
.- blockUpdatesChanged(block)¶
- Parameters:
block – bool
Notification signal of property
blockUpdatesᅟ
.- connectTo(transport)¶
- Parameters:
transport –
QWebChannelAbstractTransport
Connects the
QWebChannel
to the giventransport
object.The transport object then handles the communication between the C++ application and a remote HTML client.
Deregisters the given
object
from theQWebChannel
.Remote clients will receive a
destroyed
signal for the given object.- disconnectFrom(transport)¶
- Parameters:
transport –
QWebChannelAbstractTransport
Disconnects the
QWebChannel
from thetransport
object.See also
- propertyUpdateInterval()¶
- Return type:
int
See also
Getter of property
propertyUpdateIntervalᅟ
.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 identifierid
is then constructed.A property that is
BINDABLE
but does not have aNOTIFY
signal will have working property updates on the client side, but no mechanism to register a callback for the change notifications.Note
A current limitation is that objects must be registered before any client is initialized.
- registerObjects(objects)¶
- Parameters:
objects – Dictionary with keys of type .QString and values of type QObject.
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.
- registeredObjects()¶
- Return type:
Dictionary with keys of type .QString and values of type QObject.
Returns the map of registered objects that are published to remote clients.
- setBlockUpdates(block)¶
- Parameters:
block – bool
See also
Setter of property
blockUpdatesᅟ
.- setPropertyUpdateInterval(ms)¶
- Parameters:
ms – int
See also
Setter of property
propertyUpdateIntervalᅟ
.