PDA

View Full Version : Threading in Qt - Confusion



StarShaper
7th February 2012, 23:28
Hi,

I'm new to Qt and I am pretty confused by the way threading is done with Qt. If I look into the official docs, there is always the same way to create a thread. Create a subclass of QThread and implement your own run() function.

Even new books about Qt 4 are telling this. It is pretty much the same, like in Java.

Now I found this site.

http://labs.qt.nokia.com/2010/06/17/youre-doing-it-wrong/

and this

http://mayaposch.wordpress.com/2011/11/01/how-to-really-truly-use-qthreads-the-full-explanation/

They are telling that subclassing QThread is wrong. Why do the official docs still listing the old "wrong" way?


To create your own threads, subclass QThread and reimplement run().

http://doc.trolltech.com/4.7/qthread.html

And is it really wrong to subclass QThread? Do I have to use moveToThread()?

wysota
8th February 2012, 01:01
Why do the official docs still listing the old "wrong" way?
I would tell you but I don't like using bad words in public.


And is it really wrong to subclass QThread? Do I have to use moveToThread()?
No, it's not inherently wrong but most of the time moveToThread() is better.