Qt WebSockets

WebSocket is a web-based protocol designed to enable a two-way interactive communication session between a client application and a remote host. It enables the two entities to send data back and forth if the initial handshake succeeds.

The Qt WebSockets module provides C++ and QML interfaces that enable Qt applications to act as a server that can process WebSocket requests, or a client that can consume data received from the server, or both.

Using the Module

QML API

The QML types of the module are available through the QtWebSockets import. To use the types, add the following import statement to your .qml file:

 import QtWebSockets

C++ API

Using a Qt module's C++ API requires linking against the module library, either directly or through other dependencies. Several build tools have dedicated support for this, including CMake and qmake.

Building with CMake

Use the find_package() command to locate the needed module component in the Qt6 package:

 find_package(Qt6 REQUIRED COMPONENTS WebSockets)
 target_link_libraries(mytarget PRIVATE Qt6::WebSockets)

For more details, see the Build with CMake overview.

Building with qmake

To configure the module for building with qmake, add the module as a value of the QT variable in the project's .pro file:

 QT += websockets

Examples

Reference

Conformance

Licenses

Qt WebSockets is available under commercial licenses from The Qt Company. In addition, it is available under free software licenses. Since Qt 5.4, these free software licenses are GNU Lesser General Public License, version 3, or the GNU General Public License, version 2. See Qt Licensing for further details.