views:

138

answers:

1

Greetings , I am new to QT (4.6) and have some basic questions regarding its event mechanism.I come from Swing background so I am trying to compare it with QT.

1) Does Event-processing-loop run in seperate thread? (like EventDispatch thread in Swing) ?

2) If we open several 'QMainWindow' do they run in several threads?

3) Whats the best way to run an intensive process in a seperate thread? (like SwingWorker in Swing ? )

4) If intesive-process runs in a seperate thread ,is it possible to call UI methods like update(),repaint() from that process?

thanks in advance.

+2  A: 

1 Event loop running in the same thread

2 All UI elements are living in the same thread the one in which your main() function executed.

3 There are QThread class which allows you to have a thread with separate event loop. There is QRunable abstract class to be able to run repeating long running tasks in separate threads using QThreadPool.

4 update() and repaint() are slots and the best way to call them from separate thread is to use queued connection with a signal in your object which lives in separate thread (read QObject::connect documentation anbout connection types)

You can find all necessary information by reading documentation of classes I've mentioned.

VestniK
thanks for answer , Is using QtConcurrent::run() better than extending QThread ,QRunnable ?
umanga
Yes it should be better in most cases but I haven't yet tried it by myself.
VestniK