PDA

View Full Version : QImage problem



bluetonic
29th September 2011, 14:37
Hi,
why my programm didn't show JPG? There is definitely wrong with my code.Can the expert help me figure it out.

Thx in advance



//@main.cpp

#include <QtGui/QApplication>
#include <QLabel>

int main(int argc, char *argv[])
{
QApplication a(argc, argv);

QImage myImage;
myImage.load("file:///home/ipan/test.JPG");

QLabel myLabel;
myLabel.setPixmap(QPixmap::fromImage(myImage));


myLabel.show();

return a.exec();
}

mvuori
29th September 2011, 15:59
Help for figuring it out:
Start with the obvious one: check what .load returns. "Returns true if the image was successfully loaded; otherwise returns false."

ChrisW67
30th September 2011, 08:28
Two observations:

You don't need a file URI for a local file, just use the path.
QImage::load() takes a file name, not a URI (it uses QFile).
You don't need to go via a QImage to load QPixmap from a JPEG file.


OK, that's three.

bluetonic
30th September 2011, 09:15
Thx mvuori and ChrisQ67.

i changed the Path to:


myImage.load("/home/ipan/test.png");

and it works.

@ChrisW67

You don't need to go via a QImage to load QPixmap from a JPEG file.

This is just a test programm. Actually i have to fetch "picture file" that has been loaded with QImage class and showing it in on the screen. So i actualy need this to works.

:) thx again guys