Getting the directory path of project
Many a times we need to have the directory path where the project is stored as different people might be storing differently.
When I use
QCoreApplication::applicationFilePath()it gives me the following :
But I don't need those extra things and just need my directory path i.e.
abc/Users/arqam/GITRepo/code-base/foundation/, so how to get that.
@Arqam Where do you need it? In your pro file? In your application (if so why?)?
Hi @Arqam ,@jsulm is right,what do you really want?The directory of .pro file or the .exe file after compiled?And you want to get it in .pro file or .cpp file.They are a little different to solve each of them.
@MartinChan-0 I am looking for in my code, in my application.
In pro file I guess $$PWD does give.
@Arqam But why do you need it in your code? Who cares were the project was located?
Maybe you mean the location of your app after installation?
@Arqam Like what jsulm said it usually doesn't matter ,but if u really want u can set the proper path of code in .pro file and make the .exe file a solid path relationship to your .pro file to get the directory u want.(It seems a little foolish...)
I use it for data/gfx file loading. if run from creator it loads the data from the project folder.
That way i do not have to copy data to build folder and they are never out of sync as it uses the real deal.
in .pro i do
to use i do
#define _STR(x) #x
#define STR(x) _STR(x)
const char* Location = STR(PROJECT_LOCATION);
Disclaimer: Not sure its best way or correct way but it worked fine so far.