PDA

View Full Version : Images in QLabel



qball2k5
6th March 2006, 19:38
Hey!

I'm new to QT4...I've created my UI in the Designer. In my UI I have 5 lables that I would like to put images in. So in the pixmap property for each label...I put in the image I want. However when I compile and run the application, the images don't show up.

I can't figure out what I'm doing wrong. I'm assuming that the generated code is accurate. I don't have any code yet....except a standard main.cpp...copied from the tutorials.

Here's what is generated for each label



label = new QLabel(tabProcess);
label->setObjectName(QString::fromUtf8("label"));
label->setGeometry(QRect(140, 100, 100, 100));
label->setPixmap(QPixmap(QString::fromUtf8("stop_image_70.png")));
label->setAlignment(Qt::AlignCenter);


Any ideas?

jpn
6th March 2006, 20:10
Are the images located in the working dir (where you are running your app from)?

Add a check for pixmap loading succeeding:

QPixmap pixmap(QString::fromUtf8("stop_image_70.png"));
qtDebug() << pixmap.isNull();

qball2k5
6th March 2006, 20:23
The images are located where the executable is.

And QTDebug doesn't work...I get `qtDebug' undeclared (first use this function)

Bojan
6th March 2006, 20:37
Also, how are you running your application? If you run it from the file manager (ie. Konqueror), the working directory will probably be different than if you run it from command line. If you run it from a file manager, it is likely that the app's working directoy will be your home directory. Then the pixmap wont be found, and you'll have a null pixmap.

Use qDebug not qtDebug, I think that was a typo.

Bojan

jpn
6th March 2006, 20:39
And QTDebug doesn't work...I get `qtDebug' undeclared (first use this function)

#include <QtDebug>

qball2k5
6th March 2006, 21:28
Thanks guys!

I was able to figure it out....I had been running from Konquerer not from command line as you noted...I will run from command line from now on.

Thanks to you both/all...I don't remember how many people replied.