PDA

View Full Version : display image in qlabel



aj2903
18th February 2009, 15:45
i want to display simple image on qlabel.
My application is on C: while the images to load is on D:\images\img1.jpg
The label is made in designer .

I have tried several way to load it but is unsuccessful.
Someone Please help

Here is the code i have tried :

Code 1 :


ui.label->setPixmap(QPixmap(D:\images\img1.jpg));


Code 2:


QString img_path ="D:/images/img1.jpg";
ui.label->setPixmap(QPixmap(img_path));


Please someone help to find the error.

aamer4yu
18th February 2009, 16:28
Was your Qt built with jpeg support ?
You need to add -qt-libjpeg to configure.exe options.

Otherwise code looks fine. you can try "D:\\images\\img1.jpg"

antweb
1st July 2014, 13:20
I also can't get it to work. Tried it with png as well.
Tried adding the image in resources and then setting style sheet but still not able to view an image.
Any Help?

aamer4yu
3rd July 2014, 12:09
Are you running app outside of QtCreator ?

Does the application directory have imageformats folder ?