Unsolved 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 :abc/Users/arqam/GITRepo/code-base/foundation/build-XMLGenerator-Desktop_Qt_5_9_1_clang_64bit2-Debug/XMLGenerator.app/Contents/MacOSdef
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...)
-
Hi
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 DEFINES+=PROJECT_LOCATION="$$shell_path($$_PRO_FILE_PWD_)" 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.
-
In QT 4.11
DEFINES += PROJECT_PATH="\"$$PWD\"" // ok DEFINES+=PROJECT_LOCATION="$$shell_path($$PRO_FILE_PWD)" // fails
-
-
@mrjj said in Getting the directory path of project:
In very old Qt 4.11 ?
4.11.1in what way fails ?
return emptyIt dont know the shell_path command ?
Removing it helps -
Hi
You can use
message($$name)to check what is going on.
also do note _ in start and the end
$$_PRO_FILE_PWD_
not
PRO_FILE_PWDhttps://doc.qt.io/qt-5/qmake-variable-reference.html#pro-file-pwd