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. Relative path to absolute path
Forum Updated to NodeBB v4.3 + New Features

Relative path to absolute path

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 11.3k 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.
  • Gianluca86G Offline
    Gianluca86G Offline
    Gianluca86
    wrote on last edited by
    #1

    Hi everyone,
    I need to turn a relative path to an absolute path.
    I know how to do the opposite:

    QDir TestDir("/Home/User/TestDir");
    QString strRelative = TestDir.relativeFilePath("/Home/User/AnotherDir");
    

    So strRelative is "../AnotherDir".
    Is there a way to convert the relative file (../AnotherDir) to get to the absolute (/Home/User/AnotherDir)?

    Thanks

    1 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by
      #2

      QFileInfo("../AnotherDir").canonicalPath()

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      1 Reply Last reply
      1
      • Gianluca86G Offline
        Gianluca86G Offline
        Gianluca86
        wrote on last edited by
        #3

        It doesn't work. That gives me only " . "
        I found my solution:

        QDir TestDir("/Home/User/TestDir");
        QString AbsolutePath = TestDir.cleanPath(TestDir.absoluteFilePath("../AnotherDir"));
        

        I don't know if it's the right way, but it works.
        Thanks anyway for the Answer VRonin.

        1 Reply Last reply
        2

        • Login

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