<?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[QString to QByteArray if QString contains unicode chars]]></title><description><![CDATA[<p dir="auto">I have a QString which contains some unicode chars, and I want to convert the QString to  a QByteArray.  (Which is later converted back to a QString)</p>
<p dir="auto">If I use toLatin, toUtf8 or toLocal8bit the unicode characters are lost upon conversion.</p>
<p dir="auto">How to I convert these unicode character filled QString to a QByteArray?</p>
]]></description><link>https://forum.qt.io/topic/138589/qstring-to-qbytearray-if-qstring-contains-unicode-chars</link><generator>RSS for Node</generator><lastBuildDate>Fri, 25 Sep 2026 12:25:09 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/138589.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 14 Aug 2022 18:01:34 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to QString to QByteArray if QString contains unicode chars on Sun, 14 Aug 2022 20:00:28 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/ocgltd">@<bdi>ocgltd</bdi></a> said in <a href="/post/724824">QString to QByteArray if QString contains unicode chars</a>:</p>
<blockquote>
<p dir="auto">How would I get the multibyte QChar to become multiple bytes in the QByteArray?</p>
</blockquote>
<p dir="auto">According to <a href="https://unicodeplus.com/U+4FF0" target="_blank" rel="noopener noreferrer nofollow ugc">https://unicodeplus.com/U+4FF0</a> is encoded as  0xE4 0xBF 0xB0 when converted to utf-8</p>
]]></description><link>https://forum.qt.io/post/724830</link><guid isPermaLink="true">https://forum.qt.io/post/724830</guid><dc:creator><![CDATA[Christian Ehrlicher]]></dc:creator><pubDate>Sun, 14 Aug 2022 20:00:28 GMT</pubDate></item><item><title><![CDATA[Reply to QString to QByteArray if QString contains unicode chars on Sun, 14 Aug 2022 21:36:10 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/christian-ehrlicher">@<bdi>Christian-Ehrlicher</bdi></a> That is what I wanted, so the reason it doesn't work must be something in my code.  I'll recheck.  Thanks</p>
]]></description><link>https://forum.qt.io/post/724843</link><guid isPermaLink="true">https://forum.qt.io/post/724843</guid><dc:creator><![CDATA[ocgltd]]></dc:creator><pubDate>Sun, 14 Aug 2022 21:36:10 GMT</pubDate></item><item><title><![CDATA[Reply to QString to QByteArray if QString contains unicode chars on Sun, 14 Aug 2022 20:08:23 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/724830">QString to QByteArray if QString contains unicode chars</a>:</p>
<blockquote>
<p dir="auto">According to <a href="https://unicodeplus.com/U+4FF0" target="_blank" rel="noopener noreferrer nofollow ugc">https://unicodeplus.com/U+4FF0</a> is encoded as  0xE4 0xBF 0xB0 when converted to utf-8</p>
</blockquote>
<p dir="auto">What's right.<br />
"Hello there\xE4\xBF\xB0"</p>
]]></description><link>https://forum.qt.io/post/724831</link><guid isPermaLink="true">https://forum.qt.io/post/724831</guid><dc:creator><![CDATA[mpergand]]></dc:creator><pubDate>Sun, 14 Aug 2022 20:08:23 GMT</pubDate></item><item><title><![CDATA[Reply to QString to QByteArray if QString contains unicode chars on Sun, 14 Aug 2022 20:00:28 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/ocgltd">@<bdi>ocgltd</bdi></a> said in <a href="/post/724824">QString to QByteArray if QString contains unicode chars</a>:</p>
<blockquote>
<p dir="auto">How would I get the multibyte QChar to become multiple bytes in the QByteArray?</p>
</blockquote>
<p dir="auto">According to <a href="https://unicodeplus.com/U+4FF0" target="_blank" rel="noopener noreferrer nofollow ugc">https://unicodeplus.com/U+4FF0</a> is encoded as  0xE4 0xBF 0xB0 when converted to utf-8</p>
]]></description><link>https://forum.qt.io/post/724830</link><guid isPermaLink="true">https://forum.qt.io/post/724830</guid><dc:creator><![CDATA[Christian Ehrlicher]]></dc:creator><pubDate>Sun, 14 Aug 2022 20:00:28 GMT</pubDate></item><item><title><![CDATA[Reply to QString to QByteArray if QString contains unicode chars on Sun, 14 Aug 2022 19:46:15 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/ocgltd">@<bdi>ocgltd</bdi></a> said in <a href="/post/724824">QString to QByteArray if QString contains unicode chars</a>:</p>
<blockquote>
<p dir="auto">From the docs it sounds like to Utf 8 might create multiple bytes in the QByteArray, but upon testing it did not.</p>
</blockquote>
<p dir="auto">Why not ?</p>
<pre><code>QString s = "Hello there";
s.append(QChar(0x4FF0));

QByteArray a=s.toUtf8();
s=a;  // back to QString

qDebug()&lt;&lt;s;  // print "Hello there俰"
</code></pre>
]]></description><link>https://forum.qt.io/post/724827</link><guid isPermaLink="true">https://forum.qt.io/post/724827</guid><dc:creator><![CDATA[mpergand]]></dc:creator><pubDate>Sun, 14 Aug 2022 19:46:15 GMT</pubDate></item><item><title><![CDATA[Reply to QString to QByteArray if QString contains unicode chars on Sun, 14 Aug 2022 19:35:59 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/christian-ehrlicher">@<bdi>Christian-Ehrlicher</bdi></a> I'm not sure how to pick encoding for my QString (I could not find it in docs) if that's what you mean.  But once that is done, it looks like all of the methods for QString to convert to bytes create a single 8-bit char per character (toUtf-8, to Latin, to local 8 bit)</p>
<p dir="auto">How would I get the multibyte QChar to become multiple bytes in the QByteArray?  From the docs it sounds like to Utf 8 <strong>might</strong> create multiple bytes in the QByteArray, but upon testing it did not.</p>
]]></description><link>https://forum.qt.io/post/724824</link><guid isPermaLink="true">https://forum.qt.io/post/724824</guid><dc:creator><![CDATA[ocgltd]]></dc:creator><pubDate>Sun, 14 Aug 2022 19:35:59 GMT</pubDate></item><item><title><![CDATA[Reply to QString to QByteArray if QString contains unicode chars on Sun, 14 Aug 2022 18:51:32 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/ocgltd">@<bdi>ocgltd</bdi></a> said in <a href="/post/724821">QString to QByteArray if QString contains unicode chars</a>:</p>
<blockquote>
<p dir="auto">But I want the unicode bytes for my unicode char "俰" to appear in the byte array.</p>
</blockquote>
<p dir="auto">Then you have to use an encoding which supports this unciode char, Latin1 is not one of them but UTF-8.</p>
]]></description><link>https://forum.qt.io/post/724822</link><guid isPermaLink="true">https://forum.qt.io/post/724822</guid><dc:creator><![CDATA[Christian Ehrlicher]]></dc:creator><pubDate>Sun, 14 Aug 2022 18:51:32 GMT</pubDate></item><item><title><![CDATA[Reply to QString to QByteArray if QString contains unicode chars on Sun, 14 Aug 2022 18:39:30 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/christian-ehrlicher">@<bdi>Christian-Ehrlicher</bdi></a> I don't think I know enough to understand the details of your response.  For example, I might say:</p>
<p dir="auto">QString s = "Hello there";<br />
s.append(QChar(0x4FF0));<br />
QByteArray a = s.toLatin();</p>
<p dir="auto">But I want the unicode bytes for my unicode char "俰" to appear in the byte array.  I haven't picked any encoding (at least not knowingly)</p>
]]></description><link>https://forum.qt.io/post/724821</link><guid isPermaLink="true">https://forum.qt.io/post/724821</guid><dc:creator><![CDATA[ocgltd]]></dc:creator><pubDate>Sun, 14 Aug 2022 18:39:30 GMT</pubDate></item><item><title><![CDATA[Reply to QString to QByteArray if QString contains unicode chars on Sun, 14 Aug 2022 18:04:46 GMT]]></title><description><![CDATA[<p dir="auto">When you know which encoding the <code>unicode chars</code> have you can convert them to a proper QString with <a href="https://doc.qt.io/qt-6/qtextdecoder.html" target="_blank" rel="noopener noreferrer nofollow ugc">QTextDecoder</a>. If your QByteArray is utf-8 encoded then use QString::fromUtf8() / toUtf8().</p>
]]></description><link>https://forum.qt.io/post/724812</link><guid isPermaLink="true">https://forum.qt.io/post/724812</guid><dc:creator><![CDATA[Christian Ehrlicher]]></dc:creator><pubDate>Sun, 14 Aug 2022 18:04:46 GMT</pubDate></item></channel></rss>