diff options
author | MÃ¥rten Nordheim <marten.nordheim@qt.io> | 2022-11-15 12:30:10 +0100 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2022-11-22 12:46:14 +0000 |
commit | eb34ce2b4944ec8a3b8b088a322888b85160f7c0 (patch) | |
tree | 3e0332a58e224560c2f82a7b7a8a64a23f018696 | |
parent | e53b574e9187650b47d234f8d8d340f30b65ad24 (diff) |
Update websocket example to use the new sub-protocol feature
This also fixes the example, which was erroring out when
the server picked a sub-protocol due to a bug in QWebSocket
Task-number: QTBUG-108276
Change-Id: I582facd79bb5af7e068941d59e2d44b57a39aebc
Reviewed-by: Maurice Kalinowski <maurice.kalinowski@qt.io>
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
(cherry picked from commit e8232684191565bf32c892d5f5701194b337a94a)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r-- | examples/mqtt/websocketsubscription/websocketiodevice.cpp | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/examples/mqtt/websocketsubscription/websocketiodevice.cpp b/examples/mqtt/websocketsubscription/websocketiodevice.cpp index 696ab92..74ac77e 100644 --- a/examples/mqtt/websocketsubscription/websocketiodevice.cpp +++ b/examples/mqtt/websocketsubscription/websocketiodevice.cpp @@ -5,6 +5,8 @@ #include <QtCore/QDebug> +#include <QtWebSockets/qwebsockethandshakeoptions.h> + WebSocketIODevice::WebSocketIODevice(QObject *parent) : QIODevice(parent) { @@ -14,13 +16,10 @@ WebSocketIODevice::WebSocketIODevice(QObject *parent) bool WebSocketIODevice::open(QIODevice::OpenMode mode) { - // Cannot use an URL because of missing sub protocol support - // Have to use QNetworkRequest, see QTBUG-38742 - QNetworkRequest request; - request.setUrl(m_url); - request.setRawHeader("Sec-WebSocket-Protocol", m_protocol.constData()); + QWebSocketHandshakeOptions options; + options.setSubprotocols({m_protocol}); - m_socket.open(request); + m_socket.open(m_url, options); return QIODevice::open(mode); } |