View Full Version : Problems with the current working directory.

19th May 2011, 20:34
I'm writing a program using QtCreator that uses some files in a folder (data) in the same folder as the project folder. I'm working under linux.

In the constructor I have a line that is QFile file("./data/file.ext"). When I execute the program in the creator everything is fine.

However it fails when I launch it by double clicking the created executable because the the program thinks that it is in /home/user/Documents. (I checked by having a button that creates a message with the output of QDir::current().absoulutePath().

My question is why? and how can I change the working folder to the folder where the program executes?

Thank you very much for any input.

19th May 2011, 20:41
The current directory can be anything upon startup, but you can always find the path to your applications executable via argv[0]

Your shell most likely sets the cwd to /home/user/Documents so that directory is shown by default for any file saving/loading (a sensible decision - users will not want to manually select it everytime to save there work)