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. -
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. -
@MartinChan-0 I am looking for in my code, in my application.
In pro file I guess $$PWD does give.
-
@MartinChan-0 I am looking for in my code, in my application.
In pro file I guess $$PWD does give.
-
@MartinChan-0 I am looking for in my code, in my application.
In pro file I guess $$PWD does give.
@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.
-
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
-
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