PDA

View Full Version : refresh image in a Qlabel



prkhr4u
18th October 2013, 07:34
I have set an image using Qlabel as:


ui->label->setPixmap(QPixmap("/home/hls/Grab-build-desktop-Qt_4_8_1_in_PATH__System__Debug/rgb.bmp"));


I am performing some image processing tasks,so I want to refresh my image continuously.
Currently it is showing the image which appears at the start of the application.
The application changes the image,and I want to change the image continuously in the label

How can i Do that?

spirit
18th October 2013, 07:38
Make QPixmap as class member and reset image QLabel::setPixmap when the image has been changed.

prkhr4u
18th October 2013, 11:40
I am sorry,but couldn't understand by "Make QPixmap as class member".
I have now reset the image everytime after the image has changed.
It's only a temporary fix.
Isn't there anything where I only have to give the refernce of the file and the QLabel changes automatically whenever the picture changes.

toufic.dbouk
18th October 2013, 14:45
I am sorry,but couldn't understand by "Make QPixmap as class member".
Declare QPixmap it in the header file as a private or public... member and initialize or define it in your .cpp file then you might be able to find an approach to solve your problem.

Good Luck.

spirit
18th October 2013, 14:48
Isn't there anything where I only have to give the refernce of the file and the QLabel changes automatically whenever the picture changes.
No, there is not anything something like this. QLabel doesn't keep track of QPixmap changes, you have to reset the pixmap each time it has been changed in order to make correct rendering by QLabel.

anda_skoa
18th October 2013, 16:15
I am performing some image processing tasks,so I want to refresh my image continuously.


Do you perform those processing steps outside the displaying application?

Cheers,
_

prkhr4u
19th October 2013, 05:06
No,the processing is performed in a seperate thread,but in the same application

anda_skoa
19th October 2013, 14:40
Then you could just set the updated image on the label whenever your thread has signalled that it is finished.

No need to go through saving/loading a file, just creating a QPixmap from the QImage you are working on.

Cheers,
_

prkhr4u
21st October 2013, 04:08
Have done something similar, reset the image everytime the processing completes.
But as the application is continuous running, the thread never finishes..but only on application exit.

toufic.dbouk
21st October 2013, 08:36
But as the application is continuous running, the thread never finishes..but only on application exit.
If its a worker thread then you are doing something wrong and you have to go over the thread class and the threads object creation to figure it out.
When the Process that the thread is responsible for is done, delete the threads object and catch the threads finish signal.(you can emit your own finish signal).

Good Luck.

anda_skoa
21st October 2013, 21:20
Have done something similar, reset the image everytime the processing completes.
But as the application is continuous running, the thread never finishes..but only on application exit.

How is that related to your goal of updating the image?
Does your thread never finish processing the image?

Cheers,
_

prkhr4u
22nd October 2013, 04:09
I have one GUI thread and one worker thread. Whenever I signal 'start' from GUI thread the processing starts in worker thread and whenever I signal 'stop' the processing in worker thread stops.
After signalling 'stop' the image has to be refreshed in the GUI,
But the image processing code of start and stop code has been enclosed in a while(1) loop,hence the thread never exits..but only on the application exit.
I need to process the image every 2-3 seconds,hence i have let the thread run thorughout the application.

anda_skoa
22nd October 2013, 07:49
Ok, but that has no relation to the image processing being done at some point, i.e. when you signal stop.
The thread stops accessing the image and you use it to update the label.

Cheers,
_