[Qt-interest] Problem drawning in the GUI Thread with Data from another Thread

Sean Harmer sean.harmer at maps-technology.com
Thu Jul 2 09:20:48 CEST 2009


On Thursday 02 Jul 2009 06:27:05 O Caldas wrote:
> Hi, im working on a project where I have two threads, one Worker thread,
> that do some calculations,
> and one GUI Thread, that draw some graphics in a QWidget.
>
> The Worker thread is a class that inherits from QThread, and the GUI Thread
> is the main thread obviously.
>
> Im geting the worker thread to send a signal every end of calculation step,
> and connecting this signal
> to the method that draws the graphic in the GUI Thread
>
> like this:
>
> connect(calculator, SIGNAL(calculated(),this,
>             SLOT(updateView()));
>
> The problem is, when the calculation gets to fast, the GUI thread just bugs
> and the program terminates.
> It seems that the calculator thread starts sending too much signals and the
> GUI thread cant handle it,
> or something like this.
>
> i've tryed to use Qt::BlockingQueuedConnection but it is too slow.
>
> if someone knows what im doing wrong, or the right way to build a program
> like that please help!
It sounds like you are taking the right general approach. What does your app 
have to do in order to visualise the results? How do you get the data to the 
main thread as I notice your signal does not marshall any data across to it?

If the visualisation in the main thread really is very expensive to perform 
then maybe you should only visualise every n'th frame. You could maybe make 
this an option that the user can set depending upon the performance of their 
graphics subsystem.

Sounds like you have identified the bottle neck in your app. If you provide 
some more information we might be able to help you improve it.

Cheers,

Sean




More information about the Qt-interest-old mailing list