Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c++

qt

I'm writing a program in C++ using the Qt library. I would like to get current working directory of my program. I found the QDir::currentPath() and QCoreApplication::applicationDirPath() function but they give back the directory where the application executable is. I don't wanna get the directory that contains the application executable.

I have uploaded the image which describes the path that I want to get.

enter image description here

Does anyone has any solutions?

Thank you!

like image 255
Tan Viet Avatar asked Jul 15 '13 04:07

Tan Viet


2 Answers

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

goto: projects->[environment]->run->working directory

like image 115
user1810087 Avatar answered Oct 28 '22 08:10

user1810087


Checkout QCoreApplication::applicationDirPath(), it tries to figure out the directory the executable is in, rather than checking the current working directory

like image 24
ted Avatar answered Oct 28 '22 10:10

ted