PDA

View Full Version : Qlabel and images



eltecprogetti
29th February 2012, 18:08
I need to display jpeg images, and I thought about using a QLabel.

While I designed the label in the form, I loaded the pixmap property with a jpeg file, and the image is displayed immediately in the form in design phase.
But when I start the application, the label is blank and I don't see the jpeg image.

I added a button and when I click on the button reloading the file with these instructions:

ui->label->setPixmap(QPixmap("presentation.jpg"));
ui->label->show();

The file "presentation.jpg" is present in the source directory and also in subfolders "Debug" and "Release".

Unfortunately I don't see the jpg image on my label.

Help, please..........

wysota
29th February 2012, 18:55
You are using a path relative to the current working directory. When you launch the application the current working directory is not set to the directory containing your image.

eltecprogetti
5th March 2012, 09:36
Hi,
I am working in Windows, and I tryied with absolute path:

ui->label->setPixmap(QPixmap("c:\presentation.jpg"));
ui->label->show();

NO DIFFERENCE!!! My Qlabel is empty!!

wysota
5th March 2012, 09:39
Escape the backslash (or use a forward slash).