<?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 fill a buffer in a Thread with QtTcpSocket?]]></title><description><![CDATA[<p dir="auto">Hi, i have a problem in a thread. I want to process some data from RTLSDR device and i use the rtl tcp program to read the raw data from a tcp connection. The problem is that this program sends 1448 bytes and i cannot change the buffer.<br />
I think that if i can read the socket 10 times then i can fill a buffer 10 times and then i want to process the 14480 bytes. I am not expert and i cannot find  a solution. Any ideas?</p>
<pre><code>char *datas= new char[1448*10];
QTcpSocket *a=new QTcpSocket(this);
a-&gt;setReadBufferSize(1448);
 a-&gt;connectToHost("192.168.0.124", 5000);
if( a-&gt;waitForConnected(1000) ) {
}
pthread_mutex_lock(&amp;data_mutex);

while(1) {
while((a-&gt;waitForReadyRead(20))) {}
a-&gt;read(datas,1448);
/* Move the last part of the previous buffer, that was not processed,
 * on the start of the new buffer. */
memcpy(Modes.data, Modes.data+DATA_LEN, (FULL_LEN-1)*4);
/* Read the new data. */
memcpy(Modes.data+(FULL_LEN-1)*4, datas,DATA_LEN);
Modes.data_ready = 1;
pthread_cond_signal(&amp;data_cond);
pthread_mutex_unlock(&amp;data_mutex);
</code></pre>
<p dir="auto">}</p>
<p dir="auto">I thought with a for loop will be ok, like this :</p>
<pre><code> for(int k=0; k&lt;10; k++) {
 while((a-&gt;waitForReadyRead(20))) {}
a-&gt;read(datas+(k*1448),1448);
} 
</code></pre>
<p dir="auto">but the   while((a-&gt;waitForReadyRead(20))) {} crashes</p>
]]></description><link>https://forum.qt.io/topic/52010/how-to-fill-a-buffer-in-a-thread-with-qttcpsocket</link><generator>RSS for Node</generator><lastBuildDate>Sun, 11 Oct 2026 06:56:08 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/52010.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 09 Mar 2015 08:24:20 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to How to fill a buffer in a Thread with QtTcpSocket? on Mon, 09 Mar 2015 21:41:25 GMT]]></title><description><![CDATA[<pre><code>QTcpSocket *a=new QTcpSocket(this);
</code></pre>
<p dir="auto">"this" is wrong. please read about QThread and related documentation..</p>
<p dir="auto"><em>[edit: corrected coding tags SGaist]</em></p>
]]></description><link>https://forum.qt.io/post/264358</link><guid isPermaLink="true">https://forum.qt.io/post/264358</guid><dc:creator><![CDATA[kuzulis_]]></dc:creator><pubDate>Mon, 09 Mar 2015 21:41:25 GMT</pubDate></item><item><title><![CDATA[Reply to How to fill a buffer in a Thread with QtTcpSocket? on Mon, 09 Mar 2015 08:57:22 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/sgaist">@<bdi>SGaist</bdi></a> said:</p>
<blockquote>
<p dir="auto">Hi,</p>
<p dir="auto">Why not use signals and slots with your socket ? Just cumulate the data read in a QByteArray and when you have enough start parsing it</p>
</blockquote>
<p dir="auto">And how can i send a signal to the other thread that the data is ready ?</p>
]]></description><link>https://forum.qt.io/post/264298</link><guid isPermaLink="true">https://forum.qt.io/post/264298</guid><dc:creator><![CDATA[xmaze]]></dc:creator><pubDate>Mon, 09 Mar 2015 08:57:22 GMT</pubDate></item><item><title><![CDATA[Reply to How to fill a buffer in a Thread with QtTcpSocket? on Mon, 09 Mar 2015 08:35:12 GMT]]></title><description><![CDATA[<p dir="auto">Hi,</p>
<p dir="auto">Why not use signals and slots with your socket ? Just cumulate the data read in a QByteArray and when you have enough start parsing it</p>
]]></description><link>https://forum.qt.io/post/264291</link><guid isPermaLink="true">https://forum.qt.io/post/264291</guid><dc:creator><![CDATA[SGaist]]></dc:creator><pubDate>Mon, 09 Mar 2015 08:35:12 GMT</pubDate></item></channel></rss>