Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. General talk
  3. Brainstorm
  4. Get current working directory in a Qt application
QtWS25 Last Chance

Get current working directory in a Qt application

Scheduled Pinned Locked Moved Unsolved Brainstorm
3 Posts 3 Posters 8.4k Views
  • 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.
  • D Offline
    D Offline
    davidspen
    wrote on 16 Oct 2018, 03:27 last edited by
    #1

    I'm writing a program in C++ using the Qt library. There is a symbolic link in my home bin directory to the executable. I would like the current working directory of my program to be the directory in which I am with my terminal (ie. the result of the pwd command). I saw the QDir::currentPath() function, but it gives back the directory where the binary is.

    How can I find my current working directory?

    J 1 Reply Last reply 17 Oct 2018, 18:31
    0
    • S Offline
      S Offline
      sierdzio
      Moderators
      wrote on 16 Oct 2018, 05:55 last edited by
      #2
      qDebug() << QDir().absoluteDirPath();
      // Or, if you are inside an AppImage package:
      qDebug() << qgetenv("APPIMAGE");
      

      (Z(:^

      1 Reply Last reply
      1
      • D davidspen
        16 Oct 2018, 03:27

        I'm writing a program in C++ using the Qt library. There is a symbolic link in my home bin directory to the executable. I would like the current working directory of my program to be the directory in which I am with my terminal (ie. the result of the pwd command). I saw the QDir::currentPath() function, but it gives back the directory where the binary is.

        How can I find my current working directory?

        J Offline
        J Offline
        JonB
        wrote on 17 Oct 2018, 18:31 last edited by JonB
        #3

        @davidspen
        From exactly what you say in your question, I would not have answered it as @sierdzio has. (Unless there is something special about "if you are inside an AppImage package", I don't know about that.)

        How/where do you launch your Qt executable from?

        You say

        I would like the current working directory of my program to be the directory in which I am with my terminal (ie. the result of the pwd command).

        If you go into a terminal and type the name of an executable to run, which is then found via a symbolic link in your ~/bin which is on your PATH, that will not change the current directory. It will remain whatever it was in the terminal you launched it from. Which is what you say you want. And what QDir::currentPath() should already be delivering you:

        Returns the absolute path of the application's current directory. The current directory is the last directory set with QDir::setCurrent() or, if that was never called, the directory at which this application was started at by the parent process.

        In that case I would ask why it is not already correct?

        If you instead want something about the directory the executable is actually in, or you run it in a different way, that's a different question?

        1 Reply Last reply
        1

        2/3

        16 Oct 2018, 05:55

        • Login

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