PDA

View Full Version : Multiple threads in a single class



Matthias81
7th February 2013, 17:30
Hi,

I want to write a QObject derived class which should contain two threads. Each thread should run a different function of my class (endless loops).

I am confused which is the right and easiest way (subclassing QThread, using QThread directly, movetothread(), QtConcurrent:run).

Can someone give me a smal example?

Best regards,

Matthias

wysota
7th February 2013, 19:36
If you really need an endless loop then subclassing QThread and reimplementing run() is the way to go. But it might be that you only think you need an endless loop in which case other approaches are viable as well.

james_koley
22nd August 2013, 07:06
Its all about coherence. If you want multiple classes to do your job, running multiple threads for it, make sure that each and every class is coherent enough otherwise you've minimized reuse........