简体   繁体   English

如何将绝对路径与相对路径连接起来?

[英]How can I concatenate absolute path with relative path?

Is there any function in QDir that allow us to concatenate 2 path (one is direct path and the other one is relative) QDir 中是否有任何 function 允许我们连接 2 个路径(一个是直接路径,另一个是相对路径)

For example:例如:

path 1 is "C:/home/user1/project/data"路径 1 是“C:/home/user1/project/data”

path 2 is: "../data2/file.txt"路径 2 是:“../data2/file.txt”

the result should be a String equal to C:/home/user1/project/data2/file.txt结果应该是一个等于 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谢谢您的帮助

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM