Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-136216

QWebSocket "Invalid UTF-8 Code Encountered" Error in Qt6

    XMLWordPrintable

Details

    • All

    Description

      Description: In a scenario where two Qt programs communicate via QWebSocket, the receiving side occasionally closes the socket with the error "Invalid UTF-8 code encountered." The sending program always uses the following code to transmit UTF-8 encoded JSON documents:
      QJsonDocument doc(aQJsonObject);
      client->sendTextMessage(doc.toJson());

      This issue occurs after migrating from Qt5 to Qt6, where QTextCodec was replaced by QStringDecoder, which defaults to QStringDecoder::Flag::Stateless. It has been observed that removing the Stateless flag resolves the issue, suggesting that stateless decoding may be the cause.

      Environment:

      • OS: OpenSUSE Tumbleweed
      • Compiler: GCC 14.2
      • Qt Version: Qt6

      Suspected Cause: The change in decoding behavior between Qt5 and Qt6 (from QTextCodec to QStringDecoder with the Stateless flag) may be the cause of the error.

       

      Attachments

        For Gerrit Dashboard: QTBUG-136216
        # Subject Branch Project Status CR V

        Activity

          People

            manordheim Mårten Nordheim
            chakib Chakib Boutaghane
            Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There is 1 open Gerrit change