Relative path to absolute path



  • 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



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



  • 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.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.