PDA

View Full Version : Thread support



kiranraj
9th March 2007, 06:41
Hi guys,

Iam using Qt4.2's Theads in my application.

I have 2 threads:
1. Gui thread ( QGraphicsView)
2. Worker thread.

In my single threaded application. I have a method called CreateFabrics, which reads information in a data structure each time to create GraphicsItem ( Lot of graphicsItem are created). My application takes a lot of time in this case.

In my Multithreaded application -

Worker thread reads the populated datastructures and creates GraphicItems- ( inherited from QGraphicsItem) but i dont display it( As the doc says: Only main Thread can write to display).

My questions are -
1. Is it ok ,if i create items in other thread.
2. Will there be any performance improvement .If i run this on a multiprocessor machine.
3. How to compare the performance of single thraeded application and multithreaded
app.

Thanks

TheRonin
9th March 2007, 08:32
My questions are -
1. Is it ok ,if i create items in other thread.
2. Will there be any performance improvement .If i run this on a multiprocessor machine.
3. How to compare the performance of single thraeded application and multithreaded
app.


1. Sure, as long as you use queued connections and register the datatype (if necessary, not sure about which ones are registered by default. This needs to be done so Qt can send the datatype over a queued connection) with:
qRegisterMetaType<Type>("typeName");

2. Yes. Right now your single processor is just switching really fast between the two threads of execution. Disclaimer: this may or may not be true. Depending on the multiprocessing machine used, your threads (part of the same process) may still run on a single processor. Some multiprocessor machines allow you to schedule how the tasks should be divided amongst the processors. It should still be faster though since you've got several processors sharing the work load (provided they're not super slow compared to your single processor).

3. That depends on how you define 'performance'. If you mean execution time, you can use a QTimer to measure the time it takes for a task to be completed. I'm sure you'll find the single threaded application to be faster. If you have a very computationally intensive task to perform though, it will/may lock up your GUI.