Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Getting the directory path of project
Forum Updated to NodeBB v4.3 + New Features

Getting the directory path of project

Scheduled Pinned Locked Moved Unsolved General and Desktop
11 Posts 5 Posters 4.5k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Arqam

    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.

    jsulmJ Online
    jsulmJ Online
    jsulm
    Lifetime Qt Champion
    wrote on last edited by
    #2

    @Arqam Where do you need it? In your pro file? In your application (if so why?)?

    https://forum.qt.io/topic/113070/qt-code-of-conduct

    1 Reply Last reply
    0
    • M Offline
      M Offline
      MartinChan 0
      wrote on last edited by
      #3

      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.

      A 1 Reply Last reply
      0
      • M MartinChan 0

        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.

        A Offline
        A Offline
        Arqam
        wrote on last edited by
        #4

        @MartinChan-0 I am looking for in my code, in my application.

        In pro file I guess $$PWD does give.

        jsulmJ M 2 Replies Last reply
        0
        • A Arqam

          @MartinChan-0 I am looking for in my code, in my application.

          In pro file I guess $$PWD does give.

          jsulmJ Online
          jsulmJ Online
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #5

          @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?

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • A Arqam

            @MartinChan-0 I am looking for in my code, in my application.

            In pro file I guess $$PWD does give.

            M Offline
            M Offline
            MartinChan 0
            wrote on last edited by
            #6

            @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...)

            1 Reply Last reply
            0
            • mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by mrjj
              #7

              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.

              Q 1 Reply Last reply
              0
              • mrjjM mrjj

                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.

                Q Offline
                Q Offline
                Q139
                wrote on last edited by Q139
                #8

                In QT 4.11

                DEFINES += PROJECT_PATH="\"$$PWD\""  // ok
                DEFINES+=PROJECT_LOCATION="$$shell_path($$PRO_FILE_PWD)" // fails
                
                mrjjM 1 Reply Last reply
                0
                • Q Q139

                  In QT 4.11

                  DEFINES += PROJECT_PATH="\"$$PWD\""  // ok
                  DEFINES+=PROJECT_LOCATION="$$shell_path($$PRO_FILE_PWD)" // fails
                  
                  mrjjM Offline
                  mrjjM Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on last edited by
                  #9

                  @Q139

                  Hi
                  In very old Qt 4.11 ?

                  in what way fails ?
                  It dont know the shell_path command ?

                  Q 1 Reply Last reply
                  0
                  • mrjjM mrjj

                    @Q139

                    Hi
                    In very old Qt 4.11 ?

                    in what way fails ?
                    It dont know the shell_path command ?

                    Q Offline
                    Q Offline
                    Q139
                    wrote on last edited by Q139
                    #10

                    @mrjj said in Getting the directory path of project:

                    In very old Qt 4.11 ?
                    4.11.1

                    in what way fails ?
                    return empty

                    It dont know the shell_path command ?
                    Removing it helps

                    1 Reply Last reply
                    0
                    • mrjjM Offline
                      mrjjM Offline
                      mrjj
                      Lifetime Qt Champion
                      wrote on last edited by mrjj
                      #11

                      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_PWD

                      https://doc.qt.io/qt-5/qmake-variable-reference.html#pro-file-pwd

                      1 Reply Last reply
                      0

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved