<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Talking to Qt Threads</title>
	<atom:link href="http://thesmithfam.org/blog/2010/02/07/talking-to-qt-threads/feed/" rel="self" type="application/rss+xml" />
	<link>http://thesmithfam.org/blog/2010/02/07/talking-to-qt-threads/</link>
	<description>Your blog is probably better than mine.</description>
	<lastBuildDate>Sun, 05 Feb 2012 05:18:10 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: alex</title>
		<link>http://thesmithfam.org/blog/2010/02/07/talking-to-qt-threads/comment-page-1/#comment-145181</link>
		<dc:creator>alex</dc:creator>
		<pubDate>Sat, 03 Sep 2011 15:18:00 +0000</pubDate>
		<guid isPermaLink="false">http://thesmithfam.org/blog/?p=609#comment-145181</guid>
		<description>MyLibraryWrapper
MyLibraryWrapper

MyLibraryWrapper

#include \
#include \
#include \</description>
		<content:encoded><![CDATA[<p>MyLibraryWrapper<br />
MyLibraryWrapper</p>
<p>MyLibraryWrapper</p>
<p>#include \<br />
#include \<br />
#include \</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: alex</title>
		<link>http://thesmithfam.org/blog/2010/02/07/talking-to-qt-threads/comment-page-1/#comment-145180</link>
		<dc:creator>alex</dc:creator>
		<pubDate>Sat, 03 Sep 2011 15:17:29 +0000</pubDate>
		<guid isPermaLink="false">http://thesmithfam.org/blog/?p=609#comment-145180</guid>
		<description>i think you would like to include this in your tutorial - for beginners
#include 
#include 
#include </description>
		<content:encoded><![CDATA[<p>i think you would like to include this in your tutorial &#8211; for beginners<br />
#include<br />
#include<br />
#include</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bob ONeil</title>
		<link>http://thesmithfam.org/blog/2010/02/07/talking-to-qt-threads/comment-page-1/#comment-130570</link>
		<dc:creator>Bob ONeil</dc:creator>
		<pubDate>Thu, 07 Apr 2011 19:56:04 +0000</pubDate>
		<guid isPermaLink="false">http://thesmithfam.org/blog/?p=609#comment-130570</guid>
		<description>My understanding from others in the Qt Centre forums is that exec() may/will not pend/block.   Perhaps this is intuitive as how can a thread process events without having the event loop actually running.   From my understanding, a thread WITHOUT an event loop can signal (sender) a thread with a slot corresponding to the signal (receiver) WITH an event loop, but the receiver must be running exec() to receive the signal.   

With this in mind, I intend to have secondary threads NOT running an event loop so they will pend when not performing useful work.  The secondary threads will signal the main GUI thread which is running and event loop via a signal.  The secondary threads may communicate with each other, perhaps send heap allocated messages to other threads not running an event loop, but in this case, will not use the signal method.</description>
		<content:encoded><![CDATA[<p>My understanding from others in the Qt Centre forums is that exec() may/will not pend/block.   Perhaps this is intuitive as how can a thread process events without having the event loop actually running.   From my understanding, a thread WITHOUT an event loop can signal (sender) a thread with a slot corresponding to the signal (receiver) WITH an event loop, but the receiver must be running exec() to receive the signal.   </p>
<p>With this in mind, I intend to have secondary threads NOT running an event loop so they will pend when not performing useful work.  The secondary threads will signal the main GUI thread which is running and event loop via a signal.  The secondary threads may communicate with each other, perhaps send heap allocated messages to other threads not running an event loop, but in this case, will not use the signal method.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dave</title>
		<link>http://thesmithfam.org/blog/2010/02/07/talking-to-qt-threads/comment-page-1/#comment-128608</link>
		<dc:creator>Dave</dc:creator>
		<pubDate>Thu, 17 Mar 2011 15:22:53 +0000</pubDate>
		<guid isPermaLink="false">http://thesmithfam.org/blog/?p=609#comment-128608</guid>
		<description>Bob, have you not tried to measure the CPU usage?</description>
		<content:encoded><![CDATA[<p>Bob, have you not tried to measure the CPU usage?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bob ONeil</title>
		<link>http://thesmithfam.org/blog/2010/02/07/talking-to-qt-threads/comment-page-1/#comment-128607</link>
		<dc:creator>Bob ONeil</dc:creator>
		<pubDate>Thu, 17 Mar 2011 15:15:29 +0000</pubDate>
		<guid isPermaLink="false">http://thesmithfam.org/blog/?p=609#comment-128607</guid>
		<description>Hey Dave, quick and short question.  When implementing threading using the &quot;approved&quot; technique, and having the default thread run() method executing the thread event loop, is it your understanding that the thread will pend waiting on some activity, such as the reception of a signal()?  I want to make sure that threads are not burning processor time unless necessary.  I don&#039;t know enough about the event loop to make this accessment.   Also, feel free to clean out my comments if you want to remove some of my junk from your blog.</description>
		<content:encoded><![CDATA[<p>Hey Dave, quick and short question.  When implementing threading using the &#8220;approved&#8221; technique, and having the default thread run() method executing the thread event loop, is it your understanding that the thread will pend waiting on some activity, such as the reception of a signal()?  I want to make sure that threads are not burning processor time unless necessary.  I don&#8217;t know enough about the event loop to make this accessment.   Also, feel free to clean out my comments if you want to remove some of my junk from your blog.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bob ONeil</title>
		<link>http://thesmithfam.org/blog/2010/02/07/talking-to-qt-threads/comment-page-1/#comment-128300</link>
		<dc:creator>Bob ONeil</dc:creator>
		<pubDate>Mon, 14 Mar 2011 16:07:16 +0000</pubDate>
		<guid isPermaLink="false">http://thesmithfam.org/blog/?p=609#comment-128300</guid>
		<description>Hi Dave,

Let me clarify why the UI needs to act blocking (but perhaps not actually be blocking).   The UI presents a view of  content from a separate embedded  board.  What is displayed in the UI represents a view upon data on the embedded board that is shared over a network connection.   

The content of the GUI will be dynamic, such that when the user picks a particular GUI screen element, a volley of UDP messages with the embedded board will occur to define what will be made visible on the next displayed screen.   

My application acts to a large extent like a modern cellphone driving purely by a touchscreen under embedded Linxu (e.g. kinectic scrolling lists, icon views, multiline list controls, swipe navigation, etc.)   As such, there are 4 off touchscreen buttons that the user could press, their is a popup context menu when the user can make selectoins, etc.  While the volley is occurring, all user navigation needs to be prohibited.

But your response has me thinking, that maybe there is a better way to a act blocking, without actually blocking the event loop of the GUI thread.   

Perhaps I can find a convenient way of setting some form of flag or signal or semaphore that would be set when an outstanding communications session is underway, and block all user activity (or perhaps queue it) while this is occurring.  If you have some thoughts on this type of implementation, I would be interested.

I always believe in the KISS principle (Keep it simple stupid), and perhaps I am making it more complex than it warrants.</description>
		<content:encoded><![CDATA[<p>Hi Dave,</p>
<p>Let me clarify why the UI needs to act blocking (but perhaps not actually be blocking).   The UI presents a view of  content from a separate embedded  board.  What is displayed in the UI represents a view upon data on the embedded board that is shared over a network connection.   </p>
<p>The content of the GUI will be dynamic, such that when the user picks a particular GUI screen element, a volley of UDP messages with the embedded board will occur to define what will be made visible on the next displayed screen.   </p>
<p>My application acts to a large extent like a modern cellphone driving purely by a touchscreen under embedded Linxu (e.g. kinectic scrolling lists, icon views, multiline list controls, swipe navigation, etc.)   As such, there are 4 off touchscreen buttons that the user could press, their is a popup context menu when the user can make selectoins, etc.  While the volley is occurring, all user navigation needs to be prohibited.</p>
<p>But your response has me thinking, that maybe there is a better way to a act blocking, without actually blocking the event loop of the GUI thread.   </p>
<p>Perhaps I can find a convenient way of setting some form of flag or signal or semaphore that would be set when an outstanding communications session is underway, and block all user activity (or perhaps queue it) while this is occurring.  If you have some thoughts on this type of implementation, I would be interested.</p>
<p>I always believe in the KISS principle (Keep it simple stupid), and perhaps I am making it more complex than it warrants.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dave</title>
		<link>http://thesmithfam.org/blog/2010/02/07/talking-to-qt-threads/comment-page-1/#comment-128293</link>
		<dc:creator>Dave</dc:creator>
		<pubDate>Mon, 14 Mar 2011 14:34:16 +0000</pubDate>
		<guid isPermaLink="false">http://thesmithfam.org/blog/?p=609#comment-128293</guid>
		<description>Bob,

In the 10+ years I&#039;ve been designing user interfaces, I have *never* seen a good reason to block the event loop like that. That seems like a mis-requirement. It&#039;s one thing to prevent user input for a period of time, but blocking the event loop is something altogether different, and ill-advised in my opinion.

It is *highly* unlikely that QUdpSocket uses multi-threading under the hood. It probably uses non-blocking socket I/O.

--Dave</description>
		<content:encoded><![CDATA[<p>Bob,</p>
<p>In the 10+ years I&#8217;ve been designing user interfaces, I have *never* seen a good reason to block the event loop like that. That seems like a mis-requirement. It&#8217;s one thing to prevent user input for a period of time, but blocking the event loop is something altogether different, and ill-advised in my opinion.</p>
<p>It is *highly* unlikely that QUdpSocket uses multi-threading under the hood. It probably uses non-blocking socket I/O.</p>
<p>&#8211;Dave</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bob ONeil</title>
		<link>http://thesmithfam.org/blog/2010/02/07/talking-to-qt-threads/comment-page-1/#comment-128290</link>
		<dc:creator>Bob ONeil</dc:creator>
		<pubDate>Mon, 14 Mar 2011 14:18:15 +0000</pubDate>
		<guid isPermaLink="false">http://thesmithfam.org/blog/?p=609#comment-128290</guid>
		<description>Thanks again for your effort Dave, and your contributions to the broader Qt community.   I will give this a try and let you know my results.  

I have read the many comments on the &quot;your doing it wrong&quot; thread, and there seems to be varying opinions, perhaps some not too happy to learn they are not using what is considered best practices -- but I do not see a consensus.

One sort of unique requirement that I have is that I actually need to block my UI thread while it is retrieving data (or a timeout occurs of 300 ms), while the UDP dispatcher, presumably in another thread, feeds content to other worker threads.   Where I need some clarity is perhaps understanding more the nature of the QUdpSocket implementation under the covers.    I think it safe to say that if it is being used in asynch mode, then an event loop would be absolutely necessary.    I would also want to take advantage of the thread safe signalling using invokeMethod() as you have described in your blog.

I am not as sure of this requirement when it is being used in blocking mode.   There is a suggestion from what I have read on QUdpSocket that perhaps QUdpSocket operates in its own thread already, but I can not ascertain that from casually looking at the Qt source code.</description>
		<content:encoded><![CDATA[<p>Thanks again for your effort Dave, and your contributions to the broader Qt community.   I will give this a try and let you know my results.  </p>
<p>I have read the many comments on the &#8220;your doing it wrong&#8221; thread, and there seems to be varying opinions, perhaps some not too happy to learn they are not using what is considered best practices &#8212; but I do not see a consensus.</p>
<p>One sort of unique requirement that I have is that I actually need to block my UI thread while it is retrieving data (or a timeout occurs of 300 ms), while the UDP dispatcher, presumably in another thread, feeds content to other worker threads.   Where I need some clarity is perhaps understanding more the nature of the QUdpSocket implementation under the covers.    I think it safe to say that if it is being used in asynch mode, then an event loop would be absolutely necessary.    I would also want to take advantage of the thread safe signalling using invokeMethod() as you have described in your blog.</p>
<p>I am not as sure of this requirement when it is being used in blocking mode.   There is a suggestion from what I have read on QUdpSocket that perhaps QUdpSocket operates in its own thread already, but I can not ascertain that from casually looking at the Qt source code.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dave</title>
		<link>http://thesmithfam.org/blog/2010/02/07/talking-to-qt-threads/comment-page-1/#comment-128250</link>
		<dc:creator>Dave</dc:creator>
		<pubDate>Sun, 13 Mar 2011 22:06:27 +0000</pubDate>
		<guid isPermaLink="false">http://thesmithfam.org/blog/?p=609#comment-128250</guid>
		<description>Woops! Ignore my last comment. The default QThread implementation of the run() method actually *does* call exec(). So all you have to do is this:

QThread *myUdpThread = new QThread();
myUdpThread-&gt;start();

QUdpSocket *socket = new QUdpSocket();
socket-&gt;moveToThread(myUdpThread);

connect(socket, SIGNAL(readyRead()), ...

And that should move all UDP socket processing to the separate thread, and you can reveive its signals from your main thread (if that&#039;s what you want).

If you want to handle the data read from the socket in the separate thread, you&#039;ll have to do something like this:

class MyDataProcessor : public QObject {
Q_OBJECT
public slots:
   void readyRead() {
       // do something here
   }
};

MyDataProcessor *processor = new MyDataProcessor();
processor-&gt;moveToThread(myUdpThread);

connect(socket, SIGNAL(readyRead()), processor, SLOT(readyRead()));

--Dave</description>
		<content:encoded><![CDATA[<p>Woops! Ignore my last comment. The default QThread implementation of the run() method actually *does* call exec(). So all you have to do is this:</p>
<p>QThread *myUdpThread = new QThread();<br />
myUdpThread->start();</p>
<p>QUdpSocket *socket = new QUdpSocket();<br />
socket->moveToThread(myUdpThread);</p>
<p>connect(socket, SIGNAL(readyRead()), &#8230;</p>
<p>And that should move all UDP socket processing to the separate thread, and you can reveive its signals from your main thread (if that&#8217;s what you want).</p>
<p>If you want to handle the data read from the socket in the separate thread, you&#8217;ll have to do something like this:</p>
<p>class MyDataProcessor : public QObject {<br />
Q_OBJECT<br />
public slots:<br />
   void readyRead() {<br />
       // do something here<br />
   }<br />
};</p>
<p>MyDataProcessor *processor = new MyDataProcessor();<br />
processor->moveToThread(myUdpThread);</p>
<p>connect(socket, SIGNAL(readyRead()), processor, SLOT(readyRead()));</p>
<p>&#8211;Dave</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dave</title>
		<link>http://thesmithfam.org/blog/2010/02/07/talking-to-qt-threads/comment-page-1/#comment-128249</link>
		<dc:creator>Dave</dc:creator>
		<pubDate>Sun, 13 Mar 2011 22:04:17 +0000</pubDate>
		<guid isPermaLink="false">http://thesmithfam.org/blog/?p=609#comment-128249</guid>
		<description>Bob,

I have not yet adopted the &quot;you&#039;re doing it wrong&quot; sublcass avoidance in my QThread code. I am still sub-classing QThread. However, it seems that in order to call exec() (which is a blocking call for the life of the event loop you are creating), you *must* sub-class QThread, reimplement the run() method, and call exec() in your run() method.

I don&#039;t see any way around sub-classing QThread if you want your thread to have an event loop.

Now, you only *need* an event loop if you are receiving signals, and not necessarily if you are only emitting them (double check me on that though). However, many classes require an event loop to function properly. It&#039;s likely QUdpSocket will need an event loop running in order for it to function properly.

You really should experiment with this though, as I haven&#039;t done it (yet).

--Dave</description>
		<content:encoded><![CDATA[<p>Bob,</p>
<p>I have not yet adopted the &#8220;you&#8217;re doing it wrong&#8221; sublcass avoidance in my QThread code. I am still sub-classing QThread. However, it seems that in order to call exec() (which is a blocking call for the life of the event loop you are creating), you *must* sub-class QThread, reimplement the run() method, and call exec() in your run() method.</p>
<p>I don&#8217;t see any way around sub-classing QThread if you want your thread to have an event loop.</p>
<p>Now, you only *need* an event loop if you are receiving signals, and not necessarily if you are only emitting them (double check me on that though). However, many classes require an event loop to function properly. It&#8217;s likely QUdpSocket will need an event loop running in order for it to function properly.</p>
<p>You really should experiment with this though, as I haven&#8217;t done it (yet).</p>
<p>&#8211;Dave</p>
]]></content:encoded>
	</item>
</channel>
</rss>

