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?
Asked
Active
Viewed 1.2k times
3

Ankur
- 5,086
- 19
- 37
- 62

Shelley Shelley
- 41
- 1
- 1
- 2
2 Answers
6
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();

Mat
- 202,337
- 40
- 393
- 406
4
The simpliest way is to use QDir::absoluteFilePath
.
QDir dir(QCoreApplication::applicationDirPath());
QString absolute_file_path = dir.absoluteFilePath(relative_file_path);

Pavel Strakhov
- 39,123
- 5
- 88
- 127