[SOLVED] Qurl/QUrlQuery::addQueryItem breaks UTF-8 text
-
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. -
Hi,
Can you post an example of such a query that fails ?
-
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. -
Both would be useful
-
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: Ð ÑƒÑ Ñ ÐºÐ¸Ð¹ Ñ‚ÐµÐºÑ Ñ
-
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.
-
Perfect !
Then please, update the thread title prepending [solved] so other forum users may know a solution has been found :)