blob: 476bb0464b723f75fd88b08af5065865695c8acb (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
// Copyright (C) 2016 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Milian Wolff <milian.wolff@kdab.com>
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
/*!
\example standalone
\title Qt WebChannel Standalone Example
\ingroup qtwebchannel-examples
\image standalone-screenshot.png
\brief A simple chat between a server and a remote client running in a
browser.
\e{Standalone} demonstrates how to use the QWebChannel C++ API to
communicate with an external client. It is a simple chat between a C++
application and a remote HTML client running in your default browser.
\include examples-run.qdocinc
\section1 Communicating with a Remote Client
The C++ application sets up a QWebChannel instance and publishes a \c Core
object over it. For the remote client side, the \c {index.html} file
is opened. Both show a dialog with the list of received messages and an input
box to send messages to the other end.
The \c Core emits the \c Core::sendText() signal when the user sends
a message. The signal automatically gets propagated to the HTML client.
When the user enters a message on the HTML side, \c Core::receiveText()
is called.
All communication between the HTML client and the C++ server is done
over a WebSocket. The C++ side instantiates a QWebSocketServer and
wraps incoming QWebSocket connections in QWebChannelAbstractTransport
objects. These objects are then connected to the QWebChannel instance.
\sa {Qt WebChannel JavaScript API}
*/
|