How to concatenate an absolute path and relative path with QDir?

I have a relative path and absolute path that look something like this:

Absolute: /tmp/somedir
Relative: anotherdir/file.txt

I would like to concatenate the two (/tmp/somedir/anotherdir/file.txt) with QDir but I am not quite sure what the proper way of doing that is.

According to the documentation for QDir::absoluteFilePath:

"Returns the absolute path name of a file in the directory."

This would be ideal if all I had was a filename, but I have a relative path as well. I looked at some of the other functions on the page, but none of them seemed to be what I was looking for.

What function should I be using?

Answers


I think you are looking for filePath().

QString finalPath = QDir("/tmp/somedir").filePath("anotherdir/file.txt");

Need Your Help

JavaFX Project Structure

css javafx java-8 fxml organization

JavaFX's MVC Model by using FXML sounds awesome and all but I'm having trouble find out how to organize my project packages.

Remove key when filter collections laravel

php laravel laravel-5 laravel-5.1 laravel-5.2

I ran into a problem when using filter with Laravel 5.2, after filtering, I got some unexpected key like "0", "1", "2" ..., how can I remove it?