[Interest] QWebSocket text methods should be utf8?

Jason H jhihn at gmx.com
Fri Feb 14 20:13:24 CET 2020

After reviewing the QWebSocket spec ( https://tools.ietf.org/html/rfc6455 ) text frames are supposed to be UTF-8 encoded, which would mean that QByteArray would be the proper class.

Now I'm having to toUtf8() all the things I receive, and QString() the ones I send. I am sure this leads to some degree of madness.
I'm wondering if it would be possible to provide proper overloads:
- sendTextMessage(const QByteArray &message)
- textMessageReceived(const QByteArray &message)
- textFrameReceived(const QByteArray &frame, bool isLastFrame)

Because all I ever do is ship JSON data over them, so I wind up doing:
void  textMessageReceived(const QString &message) {
  QJsonDocument::fromJson(message.toUtf8()); // seems useless when the data coming in was already UTF-8.
 - or -

sendTextMessage(QString(QJsonDocument::fromVariant(map))); // Seems like it's being generated as 8, going 16 wide just to be sent out as 8 again.

I could be wrong, but I'm scratching my head on this one.

More information about the Interest mailing list