summaryrefslogtreecommitdiff
path: root/src/webchannel/qqmlwebchannel.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/webchannel/qqmlwebchannel.cpp')
-rw-r--r--src/webchannel/qqmlwebchannel.cpp78
1 files changed, 78 insertions, 0 deletions
diff --git a/src/webchannel/qqmlwebchannel.cpp b/src/webchannel/qqmlwebchannel.cpp
index ca99fe5..ad17ce7 100644
--- a/src/webchannel/qqmlwebchannel.cpp
+++ b/src/webchannel/qqmlwebchannel.cpp
@@ -51,6 +51,46 @@
QT_BEGIN_NAMESPACE
+/*!
+ \qmltype WebChannel
+ \instantiates QQmlWebChannel
+
+ \inqmlmodule QtWebChannel
+ \ingroup webchannel-qml
+ \brief QML interface to QWebChannel.
+ \since 5.4
+
+ The WebChannel provides a mechanism to transparently access QObject or QML objects from HTML
+ clients. All properties, signals and public slots can be used from the HTML clients.
+
+ \sa QWebChannel
+*/
+
+/*!
+ \qmlproperty QQmlListProperty<QObject> WebChannel::transports
+ A list of transport objects, which implement QWebChannelAbstractTransport. The transports
+ are used to talk to the remote clients.
+
+ \sa WebChannel::connectTo(), WebChannel::disconnectFrom()
+*/
+
+/*!
+ \qmlproperty QQmlListProperty<QObject> WebChannel::registeredObjects
+
+ \brief A list of objects which should be accessible to remote clients.
+
+ The objects must have the attached WebChannel::id property set to an identifier, under which the
+ object is then known on the HTML side.
+
+ Once registered, all signals and property changes are automatically propagated to the clients.
+ Public invokable methods, including slots, are also accessible to the clients.
+
+ If one needs to register objects which are not available when the component is created, use the
+ imperative registerObjects method.
+
+ \sa WebChannel::registerObjects(), WebChannel::id
+*/
+
class QQmlWebChannelPrivate : public QWebChannelPrivate
{
Q_DECLARE_PUBLIC(QQmlWebChannel)
@@ -60,6 +100,12 @@ public:
void _q_objectIdChanged(const QString &newId);
};
+/*!
+ \internal
+
+ Update the name of the sender object, when its attached WebChannel.id property changed.
+ This is required, since during startup the property is empty and only gets set later on.
+*/
void QQmlWebChannelPrivate::_q_objectIdChanged(const QString &newId)
{
Q_Q(QQmlWebChannel);
@@ -88,6 +134,19 @@ QQmlWebChannel::~QQmlWebChannel()
}
+/*!
+ \qmlmethod void WebChannel::registerObjects(QVariantMap objects)
+ Register objects to make them accessible to HTML clients. The key of the map is used as an identifier
+ for the object on the client side.
+
+ Once registered, all signals and property changes are automatically propagated to the clients.
+ Public invokable methods, including slots, are also accessible to the clients.
+
+ This imperative API can be used to register objects on the fly. For static objects, the declarative
+ registeredObjects property should be preferred.
+
+ \sa WebChannel::registeredObjects
+*/
void QQmlWebChannel::registerObjects(const QVariantMap &objects)
{
Q_D(QQmlWebChannel);
@@ -107,6 +166,15 @@ QQmlWebChannelAttached *QQmlWebChannel::qmlAttachedProperties(QObject *obj)
return new QQmlWebChannelAttached(obj);
}
+/*!
+ \qmlmethod void WebChannel::connectTo(QWebChannelAbstractTransport transport)
+
+ \brief Connectect to the \a transport, which represents a communication channel to a single client.
+
+ The transport object must be an implementation of QWebChannelAbstractTransport.
+
+ \sa WebChannel::transports, WebChannel::disconnectFrom()
+*/
void QQmlWebChannel::connectTo(QObject *transport)
{
if (QWebChannelAbstractTransport *realTransport = qobject_cast<QWebChannelAbstractTransport*>(transport)) {
@@ -116,6 +184,16 @@ void QQmlWebChannel::connectTo(QObject *transport)
}
}
+/*!
+ \qmlmethod void WebChannel::disconnectFrom(QWebChannelAbstractTransport transport)
+
+ \brief Disconnect the \a transport from this WebChannel.
+
+ The client will not be able to communicate with the WebChannel anymore, nor will it receive any
+ signals or property updates.
+
+ \sa WebChannel::connectTo()
+*/
void QQmlWebChannel::disconnectFrom(QObject *transport)
{
if (QWebChannelAbstractTransport *realTransport = qobject_cast<QWebChannelAbstractTransport*>(transport)) {