PDA

View Full Version : Load an image in QLabel



zeeb100
13th March 2009, 10:35
why if i execute:



QImage image(imgPath);
label->setPixmap(QPixmap::fromImage(image));


don't show image

qt is install on linux in static mode whitout demo and example...

mazurekwrc
13th March 2009, 10:55
I think that you are doing something wrong when you create object QImage, use this code and see what load function return


QImage image;
bool result = image.load( imgPath );

wysota
13th March 2009, 11:11
I would say you are using a relative path to the image and QImage simply can't find it.

zeeb100
13th March 2009, 12:01
the imgPath is

/Users/user/Desktop/img.jpg

is absolute path not relative

when i do



QImage image;
bool result = image.load( imgPath );
cout <<"result ="<<result;


result =0.

Lykurg
13th March 2009, 12:21
Is the image readable to your application? Try using QFile and get the attributes of the image file. And sorry, but check via

qWarning() << QFile::exists(imgPath);

zeeb100
13th March 2009, 12:34
qWarning return true...

Lykurg
13th March 2009, 12:54
Ok, what't the output of
QFileInfo fi(imgPath);
qWarning() << fi.permissions(); and maybe the jpg is defect, that you may open it with gimp etc. but qt fails. So for debug open the file and save it as png and try to load this in Qt.

zeeb100
13th March 2009, 12:59
jpg are correct and qWarning output is

30583

Lykurg
13th March 2009, 13:41
Sorry if I bother you, but then it must be in your code. Last debug question (with your image):
#include <QtGui>

int main(int argc, char **argv)
{
QApplication app(argc, argv);

QImage image;
bool result = image.load( "/qt/qtsdk-2009.01/qt/src/3rdparty/libtiff/html/images/smallliz.jpg" );
qWarning() << result;

QLabel lab;
lab.setPixmap(QPixmap::fromImage(image));
lab.show();

return app.exec();
}

don't work? Here on my linux machine it works as expected.

zeeb100
13th March 2009, 13:51
ok thanks the problem was installation of qt... the static mode don't load jpg becouse it find pluging thanks for help