PDA

View Full Version : QLabel does not show image



Mobility
15th June 2013, 08:55
Hi guys,

Simple case, just cannot figure out what I'm doing wrong. I'm using Qt Creator to create simple application. At the first phase, I only want it to show a image in QLabel.

This is what I have done:

1. Added the image to resource file.
2. Added a QLabel to the window.
3. From the property menu of the QLabel, I have added the image using QLabel->Pixmap option. As a result the image is shown in the Qt Creator just fine and it also shows fine when using the preview tool (ctrl+alt+r).
4. Everything seem to be fine, but when running the app the image is not shown.

I also tried setting the image to the QLabel in the cpp, but it didn't help either:


QPixmap pixmap( ":/pics/test.jpg" );
ui->label_2->setPixmap(pixmap);

Then also checked the app with Dependency Walker and nothing seems to be missing.

Any idea what's wrong?

Cheers!

wysota
15th June 2013, 09:10
http://www.qtcentre.org/faq.php?faq=qt_images#faq_qt_missing_images

saman_artorious
15th June 2013, 10:01
Hi guys,
I also tried setting the image to the QLabel in the cpp, but it didn't help either:




QLabel *love = new QLabel();
QImage myImage;
myImage.load(":/xxx.png");
QImage image = myImage.scaled(love->width(), love->height(), Qt::IgnoreAspectRatio );
love->setPixmap(QPixmap::fromImage(image));
love->show();

Mobility
15th June 2013, 13:58
Thanks for your quick replies! Problem was after all with the location of the imageformats folder. I have my sql drivers in app/plugins/sqldrivers directory, so I put the imageformats folder also under app/plugins. Correct place is app/. Wonder why Dependency Walker did not notice this... Anyway now it works, thanks again!

wysota
17th June 2013, 09:54
sqldrivers and imageformats should be in the same directory. Unless you somehow changed the default Qt behaviour for your application, your app does not search for sql plugins in the correct place. Try renaming this directory to something else and see if your app reports a missing SQL driver.