How to get the current working directory of a Qt application path?

I am writing a C ++ program using the Qt library. I would like to get the current working directory of my program. I found the function QDir :: currentPath () and QCoreApplication :: applicationDirPath () , but they return the directory in which the application executable is running. I do not want to get the directory containing the application executable.

I uploaded an image that describes the path I want to get.

enter image description here

Does anyone have any solutions?

Thanks!

+7
c ++ qt
source share
2 answers

Your application cannot know where the project is located, because it is a qt-creator option. If you want to run the binary in the project path, you need to configure the working directory inside qt-creator to the correct path. Then QDir::currentPath() will return the path you want to have.

Go to: projects-> [environment] → run-> working directory

+9
source share

Checkout QCoreApplication :: applicationDirPath () , it tries to find out the directory where the executable is located, and not check the current working directory

+2
source share

All Articles