PDA

View Full Version : Problem when load JPG



HelderC
16th November 2010, 17:24
I'm trying load a jpg image, but the code doesnt works.

Look, have this:



...
QImage *img1;
QLabel *imgLbl1;


img1->load(fileName);

imgLbl1->clear();

imgLbl1->setPixmap(QPixmap::fromImage(*img1));
...


This code only works with png, gif and bmp files but doesnt with jpg.

Any advice?

Thanks.

tbscope
16th November 2010, 17:29
Install a jpg decoder.
Or, in other words, did you compile Qt with jpg support?

HelderC
16th November 2010, 17:36
I dont know. How can i "compile Qt with jpg suppot"?

tbscope
16th November 2010, 17:40
What Qt package did you install?

HelderC
16th November 2010, 17:41
I installed only Qt SDK.

tbscope
16th November 2010, 17:42
Check if the qt/2010.05/bin/imageFormats folder contains qjpeg4.dll

HelderC
16th November 2010, 17:44
Yes, its there.

tbscope
16th November 2010, 17:50
Change your code to use a value instead of a pointer for the image.
Example:


class YourWidgetClass
{
private:
QImage img;
};

In the constructor:

img.load(fileName);
imgLbl1->setPixmap(QPixmap::fromImage(img));

If that doesn't solve your problem, the filename is wrong.

HelderC
16th November 2010, 18:06
I did what you told me. But doesnt works.
Only the bmp, png and gif works....

The path is correct otherwise how can the others formats works?

tbscope
17th November 2010, 04:28
Very simple:
1. The code you posted is not the real code of your program? But I guess it is.
2. Back to my first reply, you do not have a jpg decoder on your computer that is able to work with Qt.

I don't understand your problem. I installed the Qt SDK and showing jpg's works for me, so it is not a Qt SDK problem, it is either a problem with your code or with your system.

HelderC
17th November 2010, 10:22
I think that problem is with system.
I compiled/ran the same code just now but in linux, and its works!

tbscope, thanks for your attention!

Just a last question: Why did you say to me change the *img pointers to img? Is there any problem with pointers use? How can I know when use pointer or not?

Thanks again.