[Qt-interest] QRunnable question

Thiago Macieira thiago at kde.org
Tue May 4 14:53:13 CEST 2010


Em Terça-feira 04 Maio 2010, às 12:23:31, amulya rattan escreveu:
> Guys,
> 
> Since QRunnable doesn't inherit from QObject, can i do this:
> 
> class MyTask : public QObject, public QRunnable
> {
>     Q_OBJECT
> protected:
>     void run()
>     {
>        qDebug() << "asdfa";
>     }
> }
> 
> and expect signal/slots to work? The reason I'd like this to work is i dont
> want to use QThread, but QThreadPool. My application has a lot of threads
> already running which i'd like to take advantage of. Secondly, task is
> heavy so more the threads are working on it, better it would be.

Yes, you can do that.

Be careful though that your object is not moved to the thread it gets run on. 
So your signals should work, but your slots will maybe be called in the wrong 
thread.

In general, I'd recommend the approach above for signals only, just as with 
normal QThread.

-- 
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
  Senior Product Manager - Nokia, Qt Development Frameworks
      PGP/GPG: 0x6EF45358; fingerprint:
      E067 918B B660 DBD1 105C  966C 33F5 F005 6EF4 5358
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 190 bytes
Desc: This is a digitally signed message part.
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20100504/557c7bd2/attachment.bin 


More information about the Qt-interest-old mailing list