PDA

View Full Version : QImage



mickey
14th July 2006, 17:50
hi,
anyone know what can be the reason why sometimes this don't load the image and appear warning?


QImage img("");
cout << "text file name " << texFileName << endl;
//this above print the name "file.jpg"; it print same thing when load works and when dosn't work!!
if ( !img.load(texFileName))
qWarning( "Could not read image file ONE ");

jacek
14th July 2006, 18:11
Do you use absolute paths?

mickey
14th July 2006, 18:18
no i don't; the path printed is "image/imm.png";

jacek
14th July 2006, 19:01
no i don't;
Then use them. If you run your program from a different directory, it won't be able to find that image.

You can use QApplication::applicationDirPath() to construct an absolute path.

mickey
14th July 2006, 19:13
I change its position and texNameFIle ="../dir/image.png"


dir/myApp/images
dir/other/image.png

now it's working; under images directory doesn't work...:confused:

jacek
14th July 2006, 19:35
now it's working; under images directory doesn't work...
Does it work with absolute paths?

Do you use PNG or JPEG images?

mickey
14th July 2006, 21:29
Does it work with absolute paths?

I didin't try it; now it works with path above; maybe I changed the dir App in some place....?!

Do you use PNG or JPEG images?
both them.....thanks

jacek
14th July 2006, 21:54
maybe I changed the dir App in some place....?!
Relative paths are relative to current directory, which might change depending on how you start your program.


both them....
If JPEG images sometimes work and sometimes don't, then the problem lies in paths. If they aren't working at all, then you must make sure that you have a proper image format plugin.