Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I create an absolute file path from a QDir and a relative file path?

Tags:

c++

qt

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?

like image 619
Shelley Shelley Avatar asked Dec 29 '25 03:12

Shelley Shelley


1 Answers

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();
like image 55
Mat Avatar answered Dec 30 '25 15:12

Mat



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!