<?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[How to put QByteArray into QJsonObject]]></title><description><![CDATA[<p dir="auto">Let's say I have a custom class for which I already implemented:</p>
<pre><code>friend QDataStream &amp;operator&lt;&lt;(QDataStream&amp; out, const CustomClass&amp; c);
friend QDataStream &amp;operator&gt;&gt;(QDataStream&amp; in, CustomClass&amp; c);
</code></pre>
<p dir="auto">How can I put the QByteArray extracted using QDataSteam into a QJsonObject?<br />
Here, my not successful attempt:</p>
<pre><code>CustomClass c{};
QByteArray data;
QDataStream in(&amp;data, QIODevice::WriteOnly);
in &lt;&lt; c;

QJsonObject message;
message["type"] = QStringLiteral("login");
message["binary"] = data.data();
</code></pre>
<p dir="auto">Thanks</p>
]]></description><link>https://forum.qt.io/topic/116756/how-to-put-qbytearray-into-qjsonobject</link><generator>RSS for Node</generator><lastBuildDate>Wed, 04 Nov 2026 12:10:43 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/116756.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 07 Jul 2020 17:56:02 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to How to put QByteArray into QJsonObject on Tue, 07 Jul 2020 21:45:54 GMT]]></title><description><![CDATA[<p dir="auto">Thanks, got it.</p>
<pre><code>message["binary"] = QString(data.toBase64());
</code></pre>
]]></description><link>https://forum.qt.io/post/605398</link><guid isPermaLink="true">https://forum.qt.io/post/605398</guid><dc:creator><![CDATA[enne9]]></dc:creator><pubDate>Tue, 07 Jul 2020 21:45:54 GMT</pubDate></item><item><title><![CDATA[Reply to How to put QByteArray into QJsonObject on Tue, 07 Jul 2020 19:48:35 GMT]]></title><description><![CDATA[<p dir="auto">Hi<br />
<a href="https://doc.qt.io/qt-5/qbytearray.html#toBase64" target="_blank" rel="noopener noreferrer nofollow ugc">https://doc.qt.io/qt-5/qbytearray.html#toBase64</a></p>
]]></description><link>https://forum.qt.io/post/605370</link><guid isPermaLink="true">https://forum.qt.io/post/605370</guid><dc:creator><![CDATA[mrjj]]></dc:creator><pubDate>Tue, 07 Jul 2020 19:48:35 GMT</pubDate></item><item><title><![CDATA[Reply to How to put QByteArray into QJsonObject on Tue, 07 Jul 2020 18:03:43 GMT]]></title><description><![CDATA[<p dir="auto">Json doesn't support binary data.<br />
You can encode data to hex string or base64 string.</p>
]]></description><link>https://forum.qt.io/post/605342</link><guid isPermaLink="true">https://forum.qt.io/post/605342</guid><dc:creator><![CDATA[Bonnie]]></dc:creator><pubDate>Tue, 07 Jul 2020 18:03:43 GMT</pubDate></item></channel></rss>