PDA

View Full Version : QtConcurrent and QPainter



AwDogsgo2Heaven
14th July 2009, 01:56
Hello!

I have a few problems I have been stuck on lately and was wondering if anyone could give me any answers or advice.

1: Does Qt Concurrent::run, run the function passed in a seperate thread AND the functions called in that function? Or does it return to the main thread when a function is called in it?

2: I am running a draw function in QtConcurrent (its purpose to create a plot). However after it runs several times it eventually leads to Painter is not active errors printed on the screen. After which none of the painters work anymore.
What usually leads to these types of errors? I don't have the source on me and for that matter its very long and thick. But I was hoping I was missing something obvious. I know Pixmaps are not thread safe , so I have been using QImages. (As I've read this is a common mistake). Also no text is being rendered either.
(And for those who use QWT im basically trying to make the drawCanvas function run in a separate thread, asyncronously)

3: I understand widgets cannot be outside of the GUI thread but can you used functions from QWidget such as : contentsRect() outside the GUI thread?

If anyone can give me any insight at all about any of these I'd greatly appreciate it =). Thanks.

wysota
14th July 2009, 02:24
1: Does Qt Concurrent::run, run the function passed in a seperate thread AND the functions called in that function? Or does it return to the main thread when a function is called in it?
Everything is ran in a dedicated thread.


2: I am running a draw function in QtConcurrent (its purpose to create a plot). However after it runs several times it eventually leads to Painter is not active errors printed on the screen. After which none of the painters work anymore.
What usually leads to these types of errors?
You can't access widges (and painting them in particular) from within external threads. That's the source of your problem. The same goes with pixmaps. Images are fine as long as you don't use fonts.


3: I understand widgets cannot be outside of the GUI thread but can you used functions from QWidget such as : contentsRect() outside the GUI thread?
Reading is quite safe. The worst that can happen is that you get an outdated value.

AwDogsgo2Heaven
14th July 2009, 02:44
My printing device is a QImage though. I dont believe im printing to any widges until the thread is complete. And no fonts are being used.

wysota
14th July 2009, 08:35
We'd have to see the code to be able to tell anything more.