Getting the directory path of project
-
wrote on 16 Aug 2017, 05:49 last edited by
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.@Arqam Where do you need it? In your pro file? In your application (if so why?)?
-
wrote on 16 Aug 2017, 06:49 last edited by
-
wrote on 16 Aug 2017, 06:50 last edited by
@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 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? -
@MartinChan-0 I am looking for in my code, in my application.
In pro file I guess $$PWD does give.
wrote on 16 Aug 2017, 06:58 last edited by@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...)
-
Lifetime Qt Championwrote on 16 Aug 2017, 12:30 last edited by mrjj 3 Sept 2021, 12:23
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.
wrote on 9 Mar 2021, 11:11 last edited by Q139 3 Sept 2021, 11:16In QT 4.11
DEFINES += PROJECT_PATH="\"$$PWD\"" // ok DEFINES+=PROJECT_LOCATION="$$shell_path($$PRO_FILE_PWD)" // fails
-
In QT 4.11
DEFINES += PROJECT_PATH="\"$$PWD\"" // ok DEFINES+=PROJECT_LOCATION="$$shell_path($$PRO_FILE_PWD)" // fails
-
wrote on 9 Mar 2021, 11:29 last edited by Q139 3 Sept 2021, 11:31
@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 -
Lifetime Qt Championwrote on 9 Mar 2021, 11:58 last edited by mrjj 3 Sept 2021, 12:23
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