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. How to get current working directory in a Qt application?
Forum Updated to NodeBB v4.3 + New Features

How to get current working directory in a Qt application?

Scheduled Pinned Locked Moved General and Desktop
6 Posts 4 Posters 19.4k Views 1 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.
  • L Offline
    L Offline
    LeeMinh
    wrote on 13 Jul 2013, 11:46 last edited by
    #1

    I'm writing a program in C++ using the Qt library. I would like to get current working directory of my program (I mean that is the absolute path which contains file .pro). I saw the QDir::currentPath() function, but it gives back the directory where the binary is. I don’t get the directory that contains the application executable.

    !http://i249.photobucket.com/albums/gg220/HienBoo/qt.png(Get current working direction in QT Application)!

    Does anyone has any solutions?

    Thank you,
    Lee.

    P/S: I have uploaded the image which describes the path that I want to get.

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SergioDanielG
      wrote on 13 Jul 2013, 11:56 last edited by
      #2

      Hi LeeMinh.
      Did you try "QCoreApplication::applicationDirPath()":http://qt-project.org/doc/qt-5.0/qtcore/qcoreapplication.html#applicationDirPath
      From doc:

      bq. Returns the directory that contains the application executable.

      Regards.

      www.ftatv.com.ar El foro argentino de la TV libre

      1 Reply Last reply
      0
      • D Offline
        D Offline
        dbzhang800
        wrote on 13 Jul 2013, 13:25 last edited by
        #3

        The return value of
        @
        QDir::currentPath()
        @

        should be you current working directory.

        It equals your applicationDir or not depending on yours.

        1 Reply Last reply
        0
        • K Offline
          K Offline
          koahnig
          wrote on 13 Jul 2013, 13:57 last edited by
          #4

          welcome to devnet

          If you are starting your application in qt creator it has typically the folder of your binary as working folder or one folder below, IIRC. You can set the actual working in Qt creator in projects under the run tab. This entry points to the working directory when starting the application.

          Vote the answer(s) that helped you to solve your issue(s)

          1 Reply Last reply
          0
          • L Offline
            L Offline
            LeeMinh
            wrote on 15 Jul 2013, 02:34 last edited by
            #5

            I tried this function but this function gave back the directory where the binary is. I just wanna get current working directory, I don't get the directory that contains the application executable.
            [quote author="1+1=2" date="1373721933"]The return value of
            @
            QDir::currentPath()
            @

            should be you current working directory.

            It equals your applicationDir or not depending on yours.

            [/quote]

            1 Reply Last reply
            0
            • D Offline
              D Offline
              dbzhang800
              wrote on 16 Jul 2013, 15:30 last edited by
              #6

              Hi, seems you have misunderstand the meaning of current working directory.

              If you don't change the CWD in your application's source code, it's the directory in which your application get start. It have nothing to do with nether your source code directory nor binary directory.

              BTW, CWD can be any directory of your OS.

              1 Reply Last reply
              0

              1/6

              13 Jul 2013, 11:46

              • Login

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