Created
April 7, 2025 19:33
-
-
Save ricab/312893d71ad09c6271107eb902f48fdd to your computer and use it in GitHub Desktop.
How Qt understands Linux paths on Windows
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>> "/home/bla" | |
"/home/bla" | |
is relative? false | |
is absolute? true | |
>> "C:\\home\\bla" | |
"C:/home/bla" | |
is relative? false | |
is absolute? true | |
>> "C:\\\\home\\bla" | |
"C:/home/bla" | |
is relative? false | |
is absolute? true | |
>> "bla" | |
"bla" | |
is relative? true | |
is absolute? false | |
>> "home\\bla" | |
"home/bla" | |
is relative? true | |
is absolute? false | |
>> "home/bla" | |
"home/bla" | |
is relative? true | |
is absolute? false | |
>> "./bla" | |
"bla" | |
is relative? true | |
is absolute? false | |
>> "../bla" | |
"../bla" | |
is relative? true | |
is absolute? false | |
>> ".\\bla" | |
"bla" | |
is relative? true | |
is absolute? false | |
>> "..\\bla" | |
"../bla" | |
is relative? true | |
is absolute? false | |
>> "C:\\\\home\\bla\\..\\.\\..\\this\\and\\or\\..\\that" | |
"C:/this/and/that" | |
is relative? false | |
is absolute? true | |
>> "/home/bla/.././../this/and/or/../that" | |
"/this/and/that" | |
is relative? false | |
is absolute? true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <vector> | |
#include <QDebug> | |
#include <QDir> | |
int main() | |
{ | |
std::vector<QString> paths = {R"(/home/bla)", | |
R"(C:\home\bla)", | |
R"(C:\\home\bla)", | |
R"(bla)", | |
R"(home\bla)", | |
R"(home/bla)", | |
R"(./bla)", | |
R"(../bla)", | |
R"(.\bla)", | |
R"(..\bla)", | |
R"(C:\\home\bla\..\.\..\this\and\or\..\that)", | |
R"(/home/bla/.././../this/and/or/../that)", | |
}; | |
for (auto p : paths) | |
{ | |
qDebug() << ">> " << p; | |
qDebug() << QDir::cleanPath(p); | |
qDebug() << "is relative? " << QDir::isRelativePath(p); | |
qDebug() << "is absolute? " << QDir::isAbsolutePath(p) << "\n"; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Contrast with https://godbolt.org/z/j5f7657v4.