PDA

View Full Version : QPixmap: It is not safe to use pixmaps outside the GUI thread



bibhukalyana
14th May 2011, 08:19
Hi everyone,
I am using 3 thread (one gui(M) and two non-gui(X,Y)).In gui thread all display kind of things are there.If i want to display some thing form non gui thread then i am using the signal-slot concept.
In X i am extracting frame from web cam and continuously sending it to gui thread for display. In Y i am doing some operation on that image.In this programme i am getting "QPixmap: It is not safe to use pixmaps outside the GUI thread" and the programme is crashed. This error occurs at any place and any time in gui thread where i am trying to stop displaying image or at message box.Maximum time it occurs after a particular message box.
What can be the error ?How i solve this ?Is it due to thread synchronization ?

nish
14th May 2011, 08:24
The warning message says it all. You can not use QPixmap outside gui thread. Try to use QImage.

bibhukalyana
14th May 2011, 11:18
thanks for reply
But all QPixmap things are used inside gui thread.
The programme is working fine in windows -7 ,qt 4.7 til now.

Lykurg
14th May 2011, 12:09
But all QPixmap things are used inside gui thread.Used (=displayed) maybe, but most likely you also create one in a thread and send it to the gui thread. And this is as nish said not "possible". It could work but will crash at any time. So how do you work on the images in X and Y. What class to store do you use?

nish
14th May 2011, 14:35
send the Qimage to the gui thread and convert using Qimgae::toPixmap()

bibhukalyana
14th May 2011, 21:34
In X i am extracting frame from web cam.I am using this code:http://opencv.willowgarage.com/wiki/CameraCapture for getting the IplImage and sending this image to gui thread.In gui thread i convert the IplImage to QImage and after that i set that QImage to lable converting it to QPixmap.

nish
15th May 2011, 05:06
i did not get you. The problem is solved?

bibhukalyana
15th May 2011, 05:19
no it is not solved.
I am converting the qimage to qpixmap in gui thread.

DanH
15th May 2011, 15:04
Note that some conversions between QImage and QPixmap are "const" and "share" the image buffer. You need to be sure that such sharing is NOT occurring.

bibhukalyana
16th May 2011, 08:30
I did not get you.Can you explain more ?