How can I concatenate absolute path with relative path?

237 Views Asked by At

Is there any function in QDir that allow us to concatenate 2 path (one is direct path and the other one is relative)

For example:

path 1 is "C:/home/user1/project/data"

path 2 is : "../data2/file.txt"

the result should be a String equal to C:/home/user1/project/data2/file.txt

I tried:

QString finalPath = QDir("C:/home/user1/project/data").filePath("../data2/file.txt");

but it is not working

Thank you for your help

1

There are 1 best solutions below

0
Maram On

Here is the solution that I found:

QString concat= QDir(path1).filePath(path2);
Path = QDir::fromNativeSeparators(concat);

QString finalPath = QDir::fromNativeSeparators(finalPath);
finalPath  = QDir::cleanPath(finalPath);