[Qt-interest] connection between qthreads blocks my gui

Sean Harmer sean.harmer at maps-technology.com
Wed Dec 15 10:07:21 CET 2010


Hi,

On Tuesday 14 December 2010 18:25:03 franki wrote:
> I have some gui class (mainClass), inside that class I created two classes
> which subclass QThread, one of which is sending/receiving data from rs232,
> lets say rs232Thread, second one is sending signal to start reading from
> rs232,lets say cronThread. Connection is defined inside mainClass like
> this:
> connect(cronThread,SIGNAL(startChecking()),rs232Thread,SLOT(readWrite()),Q
> t::QueuedConnection)
> 
> Problem is, that this readWrite function blocks my entire gui when running,
> and as I read somewhere in case of QueuedConnection, the SLOT is executed
> inside receiver's thread, so why is this blocking my gui?
> 
> The only way I can do it without blocking gui is to place function
> readWrite inside run() of this rs232Thread and connect signal from
> cronThread to some function (defined in rs232Thread) which starts run().
> 
> What am I doing wrong? Is this a problem that connection between this two
> threads is defined inside mainClass (which is gui thread) ? Or there is
> something else?

This should really be on an FAQ somewhere. The section of the docs you need to 
read and understand is this:

http://doc.qt.nokia.com/latest/threads-qobject.html

As K Frank and others mentioned you need to be careful if you want to put 
slots directly onto your QThread class. To avoid confusion it is often clearer 
to use a worker QObject that lives within and has affinitiy with your QThread 
object.

Please see the attached example to see how this pattern generally works. We do 
exactly this kind of thing over rs232 comms too and it works a treat.

ATB,

Sean



-------------- next part --------------
A non-text attachment was scrubbed...
Name: threadedpoller.zip
Type: application/zip
Size: 4483 bytes
Desc: not available
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20101215/31d53e79/attachment.zip 


More information about the Qt-interest-old mailing list