Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] Qurl/QUrlQuery::addQueryItem breaks UTF-8 text
Qt 6.11 is out! See what's new in the release blog

[SOLVED] Qurl/QUrlQuery::addQueryItem breaks UTF-8 text

Scheduled Pinned Locked Moved General and Desktop
7 Posts 2 Posters 2.6k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    Violet Giraffe
    wrote on last edited by
    #1

    Consider the code:

    @query.addQueryItem("text", long_UTF8_string);
    #if QT_VERSION < QT_VERSION_CHECK(5,0,0)
    const QByteArray queryData(query.encodedQuery());
    #else
    const QByteArray queryData(query.query(QUrl::FullyEncoded).toUtf8());
    #endif
    QNetworkReply * reply = m_networkManager.post(request, queryData);@

    where query is QUrl for Qt4 and QUrlQuery for Qt5.

    The problem is that my server receives broken non-ASCII characters, as if the encoding was mistakenly converted somewhere along the way. It seems as if UTF-8 characters were parsed as ASCII. What could be the reason?
    I know for a fact the problem is in the program and not server side, I've checked it in more than 1 way. I believe the error occurs at the stage of percent-encoding the query.
    The error is the same for Qt4 and Qt5.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Can you post an example of such a query that fails ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • V Offline
        V Offline
        Violet Giraffe
        wrote on last edited by
        #3

        Do you want me to post the contents of the string that I'm trying to send, or the encoded query after the string is processed by QUrl?
        The problem occurs with any non-ASCII characters.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Both would be useful

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • V Offline
            V Offline
            Violet Giraffe
            wrote on last edited by
            #5

            This is the query:

            @query.addQueryItem("text", "Русский текст");@

            this is how it looks after encoding (can't find a way to paste without forum engine decoding it!): http://pastebin.com/Am5FJcix

            And this is how it looks after decoding: Ð ÑƒÑ Ñ ÐºÐ¸Ð¹ Ñ‚ÐµÐºÑ Ñ

            1 Reply Last reply
            0
            • V Offline
              V Offline
              Violet Giraffe
              wrote on last edited by
              #6

              Nevermind, something have changed in my project's behavior just now and I realized the problem is NOT with encoding, it was with the source QString. Case closed.

              1 Reply Last reply
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #7

                Perfect !

                Then please, update the thread title prepending [solved] so other forum users may know a solution has been found :)

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply
                0

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved