Get current working directory in a Qt application

Geoffroy picture Geoffroy · Sep 13, 2011 · Viewed 154.5k times · Source

I'm writing a program in C++ using the Qt library. There is a symbolic link in my home bin directory to the executable. I would like the current working directory of my program to be the directory in which I am with my terminal (ie. the result of the pwd command). I saw the QDir::currentPath() function, but it gives back the directory where the binary is.

How can I find my current working directory?

Answer

RedX picture RedX · Sep 13, 2011

Just tested and QDir::currentPath() does return the path from which I called my executable.

And a symlink does not "exist". If you are executing an exe from that path you are effectively executing it from the path the symlink points to.