<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Encoding problem on reply of QNetworkManager from serverside simple PHP code]]></title><description><![CDATA[<p dir="auto">So I've been doing some tests regarding encondign errors that I've seen around ñ charcater using CURL, Qt and sever side PHP. I've finally got a super minimalistic example where the error is in the Qt side ONLy. Maybe some one can help me out.</p>
<p dir="auto">The Qt Code is as follows:</p>
<pre><code>int main(int argc, char *argv[])
{

    QCoreApplication a(argc, argv);
    QString address = "http://localhost/api_test/test.php";
    QUrl url(address);
    QNetworkAccessManager manager;
    QNetworkRequest request(url);
    QNetworkReply *reply = manager.post(request, QByteArray());
    QObject::connect(reply, &amp;QNetworkReply::finished, QCoreApplication::quit);
    a.exec();
    if(reply-&gt;error() == QNetworkReply::NoError){
        qDebug() &lt;&lt; "The output";
        qDebug() &lt;&lt; QString(reply-&gt;readAll()).toUtf8();
    }
    else{
        qDebug() &lt;&lt; reply-&gt;error() &lt;&lt; reply-&gt;errorString();
    }
    delete reply;

    return 0;
}
</code></pre>
<p dir="auto">On the server side, test.php is as follows:</p>
<pre><code>&lt;?php

   $data = file_get_contents("uploaded.json");
   echo "$data\n";

?&gt;
</code></pre>
<p dir="auto">Where "uploaded.json" is a plain text file that contains</p>
<pre><code>{"name" : "Ariel ñoño", "age" : 58} 
</code></pre>
<p dir="auto">The curl command now works as expected</p>
<pre><code>ariel@ColoLaptop:/home/web/api_test$ curl http://localhost/api_test/test.php
{"name" : "Ariel ñoño", "age" : 58} 
</code></pre>
<p dir="auto">But when I run the Qt Application, this happens:</p>
<pre><code>The output
"{\"name\" : \"Ariel \xC3\xB1o\xC3\xB1o\", \"age\" : 58} \n\n"
</code></pre>
<p dir="auto">Again the ñ characters get screwed. Can anyone tell me what is wrong with the Qt Code or how can I interpret the returned byte string correctly?</p>
]]></description><link>https://forum.qt.io/topic/126698/encoding-problem-on-reply-of-qnetworkmanager-from-serverside-simple-php-code</link><generator>RSS for Node</generator><lastBuildDate>Sun, 05 Jul 2026 00:27:16 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/126698.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 16 May 2021 13:31:18 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Encoding problem on reply of QNetworkManager from serverside simple PHP code on Sun, 16 May 2021 17:39:16 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/kshegunov">@<bdi>kshegunov</bdi></a> said in <a href="/post/659949">Encoding problem on reply of QNetworkManager from serverside simple PHP code</a>:</p>
<blockquote>
<p dir="auto">It's no hack</p>
</blockquote>
<p dir="auto">I meant it's a hack to modify a QString in any way to see non-ascii characters as not hex-encoded. It works as long as the terminal supports it which will not be the case e.g. on windows.</p>
]]></description><link>https://forum.qt.io/post/659951</link><guid isPermaLink="true">https://forum.qt.io/post/659951</guid><dc:creator><![CDATA[Christian Ehrlicher]]></dc:creator><pubDate>Sun, 16 May 2021 17:39:16 GMT</pubDate></item><item><title><![CDATA[Reply to Encoding problem on reply of QNetworkManager from serverside simple PHP code on Sun, 16 May 2021 17:30:52 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/christian-ehrlicher">@<bdi>Christian-Ehrlicher</bdi></a> said in <a href="/post/659948">Encoding problem on reply of QNetworkManager from serverside simple PHP code</a>:</p>
<blockquote>
<p dir="auto">As already said otherwise - this is a hack and misuse of qDebug() and only works when the console supports the used locale. qDebug() is for debugging purposes only, nothing more.</p>
</blockquote>
<p dir="auto">It's no hack, as it is part of the public API. It is useful sometimes to see the raw output, limitations of the attached terminal aside.</p>
]]></description><link>https://forum.qt.io/post/659949</link><guid isPermaLink="true">https://forum.qt.io/post/659949</guid><dc:creator><![CDATA[kshegunov]]></dc:creator><pubDate>Sun, 16 May 2021 17:30:52 GMT</pubDate></item><item><title><![CDATA[Reply to Encoding problem on reply of QNetworkManager from serverside simple PHP code on Sun, 16 May 2021 17:29:55 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/kshegunov">@<bdi>kshegunov</bdi></a> said in <a href="/post/659947">Encoding problem on reply of QNetworkManager from serverside simple PHP code</a>:</p>
<blockquote>
<p dir="auto">Look above.</p>
</blockquote>
<p dir="auto">As already said otherwise - this is a hack and misuse of qDebug() and only works when the console supports the used locale. qDebug() is for debugging purposes only, nothing more.</p>
]]></description><link>https://forum.qt.io/post/659948</link><guid isPermaLink="true">https://forum.qt.io/post/659948</guid><dc:creator><![CDATA[Christian Ehrlicher]]></dc:creator><pubDate>Sun, 16 May 2021 17:29:55 GMT</pubDate></item><item><title><![CDATA[Reply to Encoding problem on reply of QNetworkManager from serverside simple PHP code on Sun, 16 May 2021 17:27:29 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jonb">@<bdi>JonB</bdi></a> said in <a href="/post/659945">Encoding problem on reply of QNetworkManager from serverside simple PHP code</a>:</p>
<blockquote>
<p dir="auto">Actually I think you're already doing that if you're using qDebug() &lt;&lt; QString(reply-&gt;readAll()).toUtf8();.</p>
</blockquote>
<pre><code>qDebug().noquote() &lt;&lt; "some strange text";
</code></pre>
<p dir="auto">The problem isn't the encoding, <code>QDebug</code> escapes stuff by default, as it should be.</p>
<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/aarelovich">@<bdi>aarelovich</bdi></a> said in <a href="/post/659942">Encoding problem on reply of QNetworkManager from serverside simple PHP code</a>:</p>
<blockquote>
<p dir="auto">I don't get it. Is there any way that I can get QDebug() to output the string as I wold read it?</p>
</blockquote>
<p dir="auto">Look above.</p>
]]></description><link>https://forum.qt.io/post/659947</link><guid isPermaLink="true">https://forum.qt.io/post/659947</guid><dc:creator><![CDATA[kshegunov]]></dc:creator><pubDate>Sun, 16 May 2021 17:27:29 GMT</pubDate></item><item><title><![CDATA[Reply to Encoding problem on reply of QNetworkManager from serverside simple PHP code on Sun, 16 May 2021 17:18:48 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/aarelovich">@<bdi>aarelovich</bdi></a><br />
Depends how you want to read it :)<br />
Try:</p>
<pre><code>qDebug() &lt;&lt; qUtf8Printable(whatever);
</code></pre>
<p dir="auto"><strong>EDIT</strong><br />
Actually I think you're already doing that if you're using <code>qDebug() &lt;&lt; QString(reply-&gt;readAll()).toUtf8();</code>.</p>
]]></description><link>https://forum.qt.io/post/659945</link><guid isPermaLink="true">https://forum.qt.io/post/659945</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Sun, 16 May 2021 17:18:48 GMT</pubDate></item><item><title><![CDATA[Reply to Encoding problem on reply of QNetworkManager from serverside simple PHP code on Sun, 16 May 2021 17:14:01 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/aarelovich">@<bdi>aarelovich</bdi></a> said in <a href="/post/659942">Encoding problem on reply of QNetworkManager from serverside simple PHP code</a>:</p>
<blockquote>
<p dir="auto">Is there any way that I can get QDebug() to output the string as I wold read it?</p>
</blockquote>
<p dir="auto">No since qDebug() is for debugging purposes and has to make sure that the data is printed correctly on all types of output. Therefore every non-ascii character has to be hex-encoded.</p>
]]></description><link>https://forum.qt.io/post/659943</link><guid isPermaLink="true">https://forum.qt.io/post/659943</guid><dc:creator><![CDATA[Christian Ehrlicher]]></dc:creator><pubDate>Sun, 16 May 2021 17:14:01 GMT</pubDate></item><item><title><![CDATA[Reply to Encoding problem on reply of QNetworkManager from serverside simple PHP code on Sun, 16 May 2021 17:04:58 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/christian-ehrlicher">@<bdi>Christian-Ehrlicher</bdi></a> said in <a href="/post/659934">Encoding problem on reply of QNetworkManager from serverside simple PHP code</a>:</p>
<blockquote>
<p dir="auto">n issue of qDebug() - qDebug() works as expected. You just interpreted the output wrong.</p>
</blockquote>
<p dir="auto">I don't get it. Is there any way that I can get QDebug() to output the string as I wold read it?</p>
]]></description><link>https://forum.qt.io/post/659942</link><guid isPermaLink="true">https://forum.qt.io/post/659942</guid><dc:creator><![CDATA[aarelovich]]></dc:creator><pubDate>Sun, 16 May 2021 17:04:58 GMT</pubDate></item><item><title><![CDATA[Reply to Encoding problem on reply of QNetworkManager from serverside simple PHP code on Sun, 16 May 2021 15:57:01 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/aarelovich">@<bdi>aarelovich</bdi></a> said in <a href="/post/659924">Encoding problem on reply of QNetworkManager from serverside simple PHP code</a>:</p>
<blockquote>
<p dir="auto">It was a qDebug() issue</p>
</blockquote>
<p dir="auto">It's not an issue of qDebug() - qDebug() works as expected. You just interpreted the output wrong.</p>
]]></description><link>https://forum.qt.io/post/659934</link><guid isPermaLink="true">https://forum.qt.io/post/659934</guid><dc:creator><![CDATA[Christian Ehrlicher]]></dc:creator><pubDate>Sun, 16 May 2021 15:57:01 GMT</pubDate></item><item><title><![CDATA[Reply to Encoding problem on reply of QNetworkManager from serverside simple PHP code on Sun, 16 May 2021 14:26:12 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/christian-ehrlicher">@<bdi>Christian-Ehrlicher</bdi></a> Holly Molly!!</p>
<p dir="auto">I added this to the code:</p>
<pre><code>a.exec(); // This is the line from the original code.
QFile testoutput("test_file.txt");
if (testoutput.open(QFile::WriteOnly)){
    QTextStream writer(&amp;testoutput);
    writer &lt;&lt; QString(reply-&gt;readAll()).toUtf8();
    testoutput.close();
}
</code></pre>
<p dir="auto">And this WORKED!! The file is JUST fine!!! It was a qDebug() issue, apparently.</p>
<p dir="auto">Thanks man!!</p>
]]></description><link>https://forum.qt.io/post/659924</link><guid isPermaLink="true">https://forum.qt.io/post/659924</guid><dc:creator><![CDATA[aarelovich]]></dc:creator><pubDate>Sun, 16 May 2021 14:26:12 GMT</pubDate></item><item><title><![CDATA[Reply to Encoding problem on reply of QNetworkManager from serverside simple PHP code on Sun, 16 May 2021 13:49:15 GMT]]></title><description><![CDATA[<p dir="auto">I don't see what's wrong - qDebug() hex-encodes all (possible) non-printable characters.</p>
]]></description><link>https://forum.qt.io/post/659922</link><guid isPermaLink="true">https://forum.qt.io/post/659922</guid><dc:creator><![CDATA[Christian Ehrlicher]]></dc:creator><pubDate>Sun, 16 May 2021 13:49:15 GMT</pubDate></item></channel></rss>