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?
Yes : QDir dir; Cout << dir. absolutePath() << flush; gives me the directory where the executable lives. Both QDir::currentPath() and dir. absolutePath() return the current directory of the command line.
Solution 2QDir dir("../MyProjects/ProjectB"); If the current working directory is not a sub directory of "C:\MyDevelopment\", the path will be probably invalid (not existing). This will return the path to the passed name relative to the above directory. LFName= dir.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With