Skip to content

Commit 298af82

Browse files
committed
Updated codebase to work with Qt6 out of the box
The only change needed was to the sample TestEchoClientServer.cpp application to not use deprecated QRegExp but instead use the newer QRegularExpression (which is supported in Qt5 as well). Since most of the codebase relies simply on low-level types such as QByteArray and QTcpSocket -- and since these are largely unchanged from Qt5 to Qt6 -- there doesn't appear to be any issue using WebSocket.cpp in Qt6.
1 parent fef62dd commit 298af82

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Web Socket
22

3-
A lightweight RFC 6455 (Web Socket) implementation for Qt5 by Calin Culianu <calin.culianu@gmail.com>
3+
A lightweight RFC 6455 (Web Socket) implementation for Qt5 & Qt6 by Calin Culianu <calin.culianu@gmail.com>
44

55
Key highlights:
66
- Supports both `ws://` and `wss://` Web Sockets.

examples/TestEchoClientServer.cpp

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include "../WebSocket.h"
22
#include <QFile>
33
#include <QHostAddress>
4-
#include <QRegExp>
4+
#include <QRegularExpression>
55
#include <QTcpServer>
66
#include <QSslCertificate>
77
#include <QSslConfiguration>
@@ -61,13 +61,14 @@ int main(int argc, char *argv[])
6161
// stand alone test encoding / decoding
6262
std::cout << "Enter text:\n";
6363
std::array<char, 65536> linebuf;
64-
const QRegExp hexRE("^[0-9a-fA-F]+$");
64+
const QRegularExpression hexRE("^[0-9a-fA-F]+$");
6565
while ( std::cin.getline(linebuf.data(), linebuf.size()) ) {
6666
QByteArray b = QByteArray(linebuf.data()).trimmed();
6767
QByteArray frameData;
6868

6969
try {
70-
if (hexRE.exactMatch(b)) {
70+
if (hexRE.match(b).hasMatch()) {
71+
// input was some hex encoded data
7172
frameData = QByteArray::fromHex(b);
7273
} else {
7374
frameData = WebSocket::Ser::wrapText(b, true, 260);
@@ -300,7 +301,7 @@ int main(int argc, char *argv[])
300301
qDebug("Got text frame [%s], echoing back", f.payload.constData());
301302
sock->sendText(QByteArray("ECHO ") + f.payload);
302303
} else {
303-
qDebug("Got data frame [%d bytes], echoing back", f.payload.size());
304+
qDebug("Got data frame [%d bytes], echoing back", int(f.payload.size()));
304305
sock->sendBinary(f.payload);
305306
}
306307
}

0 commit comments

Comments
 (0)