<?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 move multiple sockets to thread]]></title><description><![CDATA[<p dir="auto">Re: <a href="/topic/90577/how-move-to-thread-works">how move to thread works</a></p>
<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/sgaist">@<bdi>SGaist</bdi></a> I trying to Subscriber for different systems each system should be on 1 socket. I am able to receive data for 1 subscriber like below:</p>
<p dir="auto">MainView.cpp:</p>
<pre><code>    void MainView::startCommSubWorkerThread()
    {
        m_CommSubWorker.moveToThread(m_CommSubThread);
        connect( m_CommSubThread, &amp;QThread::started, &amp;m_CommSubWorker, &amp;CommSubWorker::process);
        m_CommSubThread-&gt;start();
        m_CommSubThread-&gt;wait(100);
    }
</code></pre>
<p dir="auto">CommSubWorker.cpp:</p>
<p dir="auto">void CommSubWorker::process()<br />
{<br />
// Call to long running task<br />
m_CommSubFuel-&gt;run();</p>
<pre><code>emit finished();
</code></pre>
<p dir="auto">}</p>
<p dir="auto">CommSubFuel.cpp:</p>
<p dir="auto">void CommSubFuel::run()<br />
{<br />
qDebug() &lt;&lt; "CommSubFuel::run()" &lt;&lt; m_CommSubInit.getFuelSocket();<br />
runReceiveFuel(m_CommSubInit.getFuelSocket());<br />
}</p>
<p dir="auto">void CommSubFuel::runReceiveFuel(void *socket)<br />
{<br />
qDebug() &lt;&lt; "runReceiveFuel-&gt;socket: " &lt;&lt; socket;<br />
int nbOfBytesReceived = 0;<br />
zmq_msg_t part;<br />
memset(&amp;part,0,sizeof(part));</p>
<pre><code>forever{
// Receive messages until no more available
do
{
    qDebug() &lt;&lt; "Size: " &lt;&lt; sizeof(SystemFuel);
    zmq_msg_init_size(&amp;part, sizeof(SystemFuel));
    // Check if a message is available to be received from socket
    nbOfBytesReceived = zmq_msg_recv(&amp;part, socket, ZMQ_DONTWAIT);
    qDebug() &lt;&lt; "In runReceive :" &lt;&lt; nbOfBytesReceived ;
    if (nbOfBytesReceived &gt; 0) {
        qDebug() &lt;&lt; "In do loop";
        parseIncomingMessageFuel(zmq_msg_data(&amp;part), nbOfBytesReceived);
    }
    zmq_msg_close(&amp;part);

} while (nbOfBytesReceived &gt; 0);

if (QThread::currentThread()-&gt;isInterruptionRequested())
    return;
}
</code></pre>
<p dir="auto">}</p>
<p dir="auto">for subscriber thread will go into forever loop, can you please solution for me to for multiple system to receive data at a time on there own individual sockets. Is it required to create individual thread for each system?</p>
]]></description><link>https://forum.qt.io/topic/135261/how-to-move-multiple-sockets-to-thread</link><generator>RSS for Node</generator><lastBuildDate>Wed, 18 Nov 2026 17:22:11 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/135261.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 24 Mar 2022 06:15:54 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to how to move multiple sockets to thread on Thu, 24 Mar 2022 20:42:32 GMT]]></title><description><![CDATA[<p dir="auto">Hi,</p>
<p dir="auto">You are not using Qt sockets there since you are using ZMQ. You should take a look at this <a href="https://www.ics.com/blog/build-high-performance-messaging-service-qt-and-ios" target="_blank" rel="noopener noreferrer nofollow ugc">article from ICS</a> implementing an application using ZMQ and Qt.</p>
]]></description><link>https://forum.qt.io/post/707573</link><guid isPermaLink="true">https://forum.qt.io/post/707573</guid><dc:creator><![CDATA[SGaist]]></dc:creator><pubDate>Thu, 24 Mar 2022 20:42:32 GMT</pubDate></item><item><title><![CDATA[Reply to how to move multiple sockets to thread on Thu, 24 Mar 2022 06:38:34 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/mahi1990">@<bdi>Mahi1990</bdi></a> said in <a href="/post/707478">how to move multiple sockets to thread</a>:</p>
<blockquote>
<p dir="auto">m_CommSubThread-&gt;wait(100);</p>
</blockquote>
<p dir="auto">Why do you wait for the thread?</p>
<p dir="auto">Why do you have an endless loop? Such loops block the Qt event loop!</p>
<p dir="auto">I suggest you take a look at this example: <a href="https://doc.qt.io/qt-5/qtnetwork-threadedfortuneserver-example.html" target="_blank" rel="noopener noreferrer nofollow ugc">https://doc.qt.io/qt-5/qtnetwork-threadedfortuneserver-example.html</a></p>
]]></description><link>https://forum.qt.io/post/707482</link><guid isPermaLink="true">https://forum.qt.io/post/707482</guid><dc:creator><![CDATA[jsulm]]></dc:creator><pubDate>Thu, 24 Mar 2022 06:38:34 GMT</pubDate></item></channel></rss>