Skip to content

Instantly share code, notes, and snippets.

@ricab
Created April 7, 2025 19:33
Show Gist options
  • Save ricab/312893d71ad09c6271107eb902f48fdd to your computer and use it in GitHub Desktop.
Save ricab/312893d71ad09c6271107eb902f48fdd to your computer and use it in GitHub Desktop.
How Qt understands Linux paths on Windows
>> "/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
#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;
}
@ricab
Copy link
Author

ricab commented Apr 7, 2025

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment