<?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[is the qdatastream thread safe or not ?]]></title><description><![CDATA[<p dir="auto">I just used the QJsonObject in the  new std::thread .and the heob debugger give me  a tip:</p>
<pre><code>&lt;unique&gt;0x000860F2&lt;/unique&gt;
  &lt;tid&gt;26&lt;/tid&gt;
  &lt;kind&gt;Leak_DefinitelyLost&lt;/kind&gt;
  &lt;xwhat&gt;
    &lt;text&gt;160816 bytes in 1 blocks are lost in loss record 12 of 81505 (#549106)&lt;/text&gt;
    &lt;leakedbytes&gt;160816&lt;/leakedbytes&gt;
    &lt;leakedblocks&gt;1&lt;/leakedblocks&gt;
  &lt;/xwhat&gt;
  &lt;stack&gt;
    &lt;frame&gt;
      &lt;fn&gt;malloc&lt;/fn&gt;
    &lt;/frame&gt;
    &lt;frame&gt;
      &lt;ip&gt;0x673B1B17&lt;/ip&gt;
      &lt;obj&gt;D:\program\qt\5.14.1\msvc2017\bin\Qt5Cored.dll&lt;/obj&gt;
      &lt;fn&gt;class QDataStream &amp;amp; operator&amp;gt;&amp;gt;(class QDataStream &amp;amp;,class QJsonObject &amp;amp;)&lt;/fn&gt;
    &lt;/frame&gt;
    &lt;frame&gt;
      &lt;ip&gt;0x673AEDD2&lt;/ip&gt;
      &lt;obj&gt;D:\program\qt\5.14.1\msvc2017\bin\Qt5Cored.dll&lt;/obj&gt;
      &lt;fn&gt;bool QJsonObject::detach2(unsigned int)&lt;/fn&gt;
    &lt;/frame&gt;
    &lt;frame&gt;
      &lt;ip&gt;0x673B09F3&lt;/ip&gt;
      &lt;obj&gt;D:\program\qt\5.14.1\msvc2017\bin\Qt5Cored.dll&lt;/obj&gt;
      &lt;fn&gt;class QDataStream &amp;amp; operator&amp;gt;&amp;gt;(class QDataStream &amp;amp;,class QJsonObject &amp;amp;)&lt;/fn&gt;
    &lt;/frame&gt;
    &lt;frame&gt;
      &lt;ip&gt;0x673B0D92&lt;/ip&gt;
      &lt;obj&gt;D:\program\qt\5.14.1\msvc2017\bin\Qt5Cored.dll&lt;/obj&gt;
      &lt;fn&gt;class QDataStream &amp;amp; operator&amp;gt;&amp;gt;(class QDataStream &amp;amp;,class QJsonObject &amp;amp;)&lt;/fn&gt;
    &lt;/frame&gt;
    &lt;frame&gt;
      &lt;ip&gt;0x673AEA5E&lt;/ip&gt;
      &lt;obj&gt;D:\program\qt\5.14.1\msvc2017\bin\Qt5Cored.dll&lt;/obj&gt;
      &lt;fn&gt;class QJsonObject::iterator QJsonObject::insert(class QStringView,class QJsonValue const &amp;amp;)&lt;/fn&gt;
    &lt;/frame&gt;
    &lt;frame&gt;
      &lt;ip&gt;0x673AE96B&lt;/ip&gt;
      &lt;obj&gt;D:\program\qt\5.14.1\msvc2017\bin\Qt5Cored.dll&lt;/obj&gt;
      &lt;fn&gt;class QJsonObject::iterator QJsonObject::insert(class QString const &amp;amp;,class QJsonValue const &amp;amp;)&lt;/fn&gt;
    &lt;/frame&gt;
</code></pre>
<p dir="auto">I just use the std::mutex to lock the data write and read.<br />
so I think maybe its not safe with using the  std::mutex to read and write the qjsonobject? dose i need to change the std::mutex into the QMutex ?</p>
]]></description><link>https://forum.qt.io/topic/163239/is-the-qdatastream-thread-safe-or-not</link><generator>RSS for Node</generator><lastBuildDate>Thu, 05 Nov 2026 03:51:10 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/163239.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 15 Sep 2025 10:13:40 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to is the qdatastream thread safe or not ? on Tue, 16 Sep 2025 02:02:05 GMT]]></title><description><![CDATA[<p dir="auto">In fact.<br />
I wrote the data in a new std::thread and then post the result to the qt ui main loop.<br />
Now I just used the emit way to send the data to the ui loop.</p>
]]></description><link>https://forum.qt.io/post/831627</link><guid isPermaLink="true">https://forum.qt.io/post/831627</guid><dc:creator><![CDATA[nicker player]]></dc:creator><pubDate>Tue, 16 Sep 2025 02:02:05 GMT</pubDate></item><item><title><![CDATA[Reply to is the qdatastream thread safe or not ? on Mon, 15 Sep 2025 15:36:34 GMT]]></title><description><![CDATA[<p dir="auto">When you only access an object from a single thread why do you ask about thread safeness and mutexes here?</p>
]]></description><link>https://forum.qt.io/post/831611</link><guid isPermaLink="true">https://forum.qt.io/post/831611</guid><dc:creator><![CDATA[Christian Ehrlicher]]></dc:creator><pubDate>Mon, 15 Sep 2025 15:36:34 GMT</pubDate></item><item><title><![CDATA[Reply to is the qdatastream thread safe or not ? on Mon, 15 Sep 2025 12:35:01 GMT]]></title><description><![CDATA[<p dir="auto">so if I used the std::thread and the std::mutex to lock the data.what should I do the make sure that writting and reading the data is safe .</p>
<pre><code>class A:QObject{
....
private:
       QJsonObject t_data;
public:
       void writing(const QString &amp; value){
                t_data.insert("data",value);
                do_otherthings_such_as_update_the_ui_value();
        }
}

//std thread functions what is detached from the main thread.
int testfunction(){
       //heres  to modify and send the data into the writing method.
       A aobject;
       aobject.writing("somevalue");
}
</code></pre>
<p dir="auto">so dose i need to lock the the t_data by using the QMutex or using the emit method  to to the other data what is in the main thread instead of using the lock way.what should i do.please.</p>
]]></description><link>https://forum.qt.io/post/831603</link><guid isPermaLink="true">https://forum.qt.io/post/831603</guid><dc:creator><![CDATA[nicker player]]></dc:creator><pubDate>Mon, 15 Sep 2025 12:35:01 GMT</pubDate></item><item><title><![CDATA[Reply to is the qdatastream thread safe or not ? on Mon, 15 Sep 2025 10:15:48 GMT]]></title><description><![CDATA[<p dir="auto">No Qt object or function is thread safe except it is explicitly stated in the documentation.</p>
]]></description><link>https://forum.qt.io/post/831595</link><guid isPermaLink="true">https://forum.qt.io/post/831595</guid><dc:creator><![CDATA[Christian Ehrlicher]]></dc:creator><pubDate>Mon, 15 Sep 2025 10:15:48 GMT</pubDate></item></channel></rss>