<?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[QUDPsocket paradigma looks confusing]]></title><description><![CDATA[<p dir="auto">This code taken from the net looks easy to understand. But I doubt that!</p>
<p dir="auto">connect(&amp;udpSocket, SIGNAL(readyRead()),<br />
this, SLOT(processPendingDatagrams()))</p>
<p dir="auto">void WeatherStation::processPendingDatagrams()<br />
{<br />
QByteArray datagram;</p>
<p dir="auto">do {<br />
datagram.resize(udpSocket.pendingDatagramSize());<br />
udpSocket.readDatagram(datagram.data(), datagram.size());<br />
} while (udpSocket.hasPendingDatagrams());</p>
<p dir="auto">etc</p>
<p dir="auto">}</p>
<p dir="auto">Basically while (udpSocket.hasPendingDatagrams()) looks a bit odd. Let say that I have two or three datagrams.  How many times connect will signal that<br />
has datagram to be processed? ProcessPending digram will process one or all datagrams  arrived? Or in this case I might read and read second datagram on the top of the first one?<br />
That might not be what I wanted?</p>
]]></description><link>https://forum.qt.io/topic/93721/qudpsocket-paradigma-looks-confusing</link><generator>RSS for Node</generator><lastBuildDate>Thu, 16 Apr 2026 16:45:41 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/93721.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 15 Aug 2018 16:45:27 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to QUDPsocket paradigma looks confusing on Wed, 15 Aug 2018 21:32:34 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jonb">@<bdi>JonB</bdi></a> you might be right.<br />
<a href="http://www.informit.com/articles/article.aspx?p=1405552&amp;seqNum=4" target="_blank" rel="noopener noreferrer nofollow ugc">http://www.informit.com/articles/article.aspx?p=1405552&amp;seqNum=4</a><br />
in fact I could see that if there is pending datagram, read it, and then again, and as well process after each if statement. Ok. I understand it now.</p>
]]></description><link>https://forum.qt.io/post/476341</link><guid isPermaLink="true">https://forum.qt.io/post/476341</guid><dc:creator><![CDATA[Tamis2018]]></dc:creator><pubDate>Wed, 15 Aug 2018 21:32:34 GMT</pubDate></item><item><title><![CDATA[Reply to QUDPsocket paradigma looks confusing on Wed, 15 Aug 2018 17:57:31 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/tamis2018">@<bdi>Tamis2018</bdi></a> have you tried running the whole "code taken from the net"? Does it work?</p>
<p dir="auto">You may want to check <a href="http://doc.qt.io/qt-5/qudpsocket.html" target="_blank" rel="noopener noreferrer nofollow ugc">QUdpSocket documentation</a>, which shows a quite similar way to read arriving datagrams.</p>
<p dir="auto">Essentially, you act on readyRead() signal <em>"emitted whenever datagrams arrive"</em> and loop until there are no more datagrams to read...</p>
]]></description><link>https://forum.qt.io/post/476309</link><guid isPermaLink="true">https://forum.qt.io/post/476309</guid><dc:creator><![CDATA[Pablo J. Rogina]]></dc:creator><pubDate>Wed, 15 Aug 2018 17:57:31 GMT</pubDate></item><item><title><![CDATA[Reply to QUDPsocket paradigma looks confusing on Wed, 15 Aug 2018 17:13:39 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/tamis2018">@<bdi>Tamis2018</bdi></a><br />
Not sure what you mean/what the problem is! :)</p>
<blockquote>
<p dir="auto">This code taken from the net</p>
</blockquote>
<p dir="auto"><em>Then why not tell us the link??</em>  Or do you enjoy setting us puzzles? :)</p>
<blockquote>
<p dir="auto">Basically while (udpSocket.hasPendingDatagrams()) looks a bit odd.</p>
</blockquote>
<p dir="auto">Why?!</p>
<blockquote>
<p dir="auto">Let say that I have two or three datagrams. How many times connect will signal that<br />
has datagram to be processed?</p>
</blockquote>
<p dir="auto">The signal is sent on <code>readyRead()</code>.</p>
<blockquote>
<p dir="auto">ProcessPending digram will process one or all datagrams arrived?</p>
</blockquote>
<p dir="auto"><code>processPendingDatagrams()</code> has a loop.  It will process as many datagrams as it finds are available, then it will exit.</p>
<blockquote>
<p dir="auto">Or in this case I might read and read second datagram on the top of the first one?<br />
That might not be what I wanted?</p>
</blockquote>
<p dir="auto">The code is just showing you how to read each datagram into a <code>QByteArray</code>.  Yes, each one will overwrite in that buffer.  I suspect the "code taken from the net" you mention intended you to do your processing of that data in the loop, after you have read one datagram into the buffer before you go read the next one on top of it!</p>
]]></description><link>https://forum.qt.io/post/476302</link><guid isPermaLink="true">https://forum.qt.io/post/476302</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Wed, 15 Aug 2018 17:13:39 GMT</pubDate></item></channel></rss>