[Qt-interest] Fwd: Re: Thread calling Thread and Signal/Slots

Thiago Macieira thiago.macieira at trolltech.com
Mon Mar 30 18:13:03 CEST 2009


Em Segunda-feira 30 Março 2009, às 18:06:59, Sean Harmer escreveu:
> If I call exec() then my thread is not doing anything anymore because it
> stops at exec()
>
>     void run()
>     {      
>         exec();
>         m_stopped = false;
>         Init();
>         Calculation();
>         emit finishedCalculation(!m_stopped);
>         m_stopped = true;
>     }
>
>
> so, how is exec() supposed to work ???

If you use exec(), you shouldn't place code in run().

You should react to signals sent. And then do the work in those slots.

However, your code doesn't look like it needs to receive signals. So you don't 
need exec() there.

One more thing: that m_stopped variable is not protected by any mutexes. Is it 
volatile?

-- 
Thiago Macieira - thiago.macieira (AT) nokia.com
  Senior Product Manager - Nokia, Qt Software
     Sandakerveien 116, NO-0402 Oslo, Norway
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part.
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090330/0ea3797c/attachment.bin 


More information about the Qt-interest-old mailing list