<?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[Problems with network connection, signals and threads]]></title><description><![CDATA[<p dir="auto">I have developed a network connection with unittests and in the test everything works as expected.</p>
<p dir="auto">Now I put the connection part in the application and there I get problems. It took a while until all event-callbacks were executed in the right thread. Because of the fragmentation of the network transfer by the different signals I store the message in a private member variable. Then in the corresponding callback the member variable is read and sent.</p>
<p dir="auto">My problem is that the content of the member variable changes between event callbacks. For this I have set data breakpoints on the variable to find out who is poaching in memory.<br />
At startup, the data breakpoint hits once at an unexpected place:<br />
Thread QDBusConnection, Stack QDBusConnectionTypeInfo -&gt; QByteArray</p>
<p dir="auto">This is before the variable is even created. The variable is a pointer that is set to 0 in the constructor. Then the first time a message is sent, a QByteArray is created on the pointer and filled with data.<br />
Then a connection is established with a QTcpSocket (connectToHost). At OnConnected-callback the message should be sent, but now the QByteArray already has a different content.</p>
<p dir="auto">I checked if the class is the same instance and if everything happens in the right thread. Then I checked if maybe the destructor is called. None of this is true. There is also no friend declaration that a stranger could use to change the private variable ...</p>
<p dir="auto">Now I'm at a loss. How can I find out who is screwing up my memory space and why?</p>
]]></description><link>https://forum.qt.io/topic/140294/problems-with-network-connection-signals-and-threads</link><generator>RSS for Node</generator><lastBuildDate>Sat, 24 Oct 2026 15:03:51 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/140294.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 25 Oct 2022 04:04:40 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Problems with network connection, signals and threads on Wed, 26 Oct 2022 15:38:43 GMT]]></title><description><![CDATA[<p dir="auto">Hi and thank you for your attention.</p>
<p dir="auto">No static was not the problem.<br />
But triggered by your question, I found it.</p>
<p dir="auto">I built a blocking socket variant and then on debugging I saw, that the message body was clobbered at socket.connectToHost ...</p>
<p dir="auto">I treated that possiblity as impossible and started a wider search, which leaded to my fault:<br />
I used QByteArray::setRawData() and thought, that would copy the source buffer. But that's not true (RTFM). I had to use the constructor with buffer-pointer and buffer size to obtain a deep buffer copy.</p>
<p dir="auto">Now it works.</p>
]]></description><link>https://forum.qt.io/post/734164</link><guid isPermaLink="true">https://forum.qt.io/post/734164</guid><dc:creator><![CDATA[django.Reinhard]]></dc:creator><pubDate>Wed, 26 Oct 2022 15:38:43 GMT</pubDate></item><item><title><![CDATA[Reply to Problems with network connection, signals and threads on Tue, 25 Oct 2022 19:32:41 GMT]]></title><description><![CDATA[<p dir="auto">Hi,</p>
<p dir="auto">Anything "static" in your design ?</p>
]]></description><link>https://forum.qt.io/post/734073</link><guid isPermaLink="true">https://forum.qt.io/post/734073</guid><dc:creator><![CDATA[SGaist]]></dc:creator><pubDate>Tue, 25 Oct 2022 19:32:41 GMT</pubDate></item></channel></rss>