0

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

Maram
  • 31
  • 10
  • 1
    I didn't find a function till now but when I use the result later to open the file it is working since C:/home/user1/project/data/../data2/file.txt is same as C:/home/user1/project/data2/file.txt – Maram Jan 05 '21 at 11:19

1 Answers1

1

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);

Maram
  • 31
  • 10