PDA

View Full Version : relative file name



benlyboy
27th June 2010, 07:38
hi all could do with some help

I can't get this to work


self.setWindowIcon(QIcon("file.jpg"))

if i write it with a full path it works, but with a relative path like this it won't.

am i doing something wrong or does QT not except relative file name?

thanks for any help

squidge
27th June 2010, 08:03
Or perhaps it simply can't find the file?

Instead of launching from Qt Creator, launch the exe yourself with the file.jpg in the same directory.

benlyboy
27th June 2010, 14:34
Hi thanks for the reply

Yes I tried opening the exe with the jpg in the same fire and no go.

I should say here that the the system that i am using is a linux system, and i now think this might be the problem.

I ran some tests, and found that if I place the image file in my home directory it works no matter where i place the exe file. It seem the my system is looking for any file that has no full path from the home directory. I tested this further by removing the image file from the home directory and then adding just the subdirectory to a file name and all works great.

I tried my program on a windows system and it works ok so I guess thats what is going on

It seem this maybe a Linux problem rather than QT has anyone else see this with linux...?

ChrisW67
28th June 2010, 03:44
The relative path is not relative to the location of the executable. Qt will be looking in the current working directory of the application process for the file. By default the application gains the current working directory of the process that launched it. If you launch it manually from your home directory then that is where it looks for the file. If Qt Creator launches the application then the current working directory may be different.

If you want to find the location of the executable to build a path to your file then use QCoreApplication::applicationDirPath().