In my program I have a QDir representing the location of the executable using QCoreApplication::applicationDirPath() and a QString that represents a path to a file relative to the executable directory (using .. , etc.). How do I turn this information into an absolute file path to the same file?
You can use QFileInfo for that, use the constructor that takes a QDir and a QString, then call absoluteFilePath or canonicalFilePath depending on what you want exactly.
QDir dir;
// ...
QString file;
// ...
QFileInfo fi(dir, file);
QString canonical = fi.canonicalFilePath();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With