How to build a full path string (safely) from separate strings?

c++, filepath, qt

Solution

Check out QDir for that:

QString path = QDir(dirPath).filePath(fileName);

Problem

Does C++ have any equivalent to python's function `os.path.join`? Basically, I'm looking for something that combines two (or more) parts of a file path so that you don't have to worry about making sure the two parts fit together perfectly. If it's in Qt, that would be cool too. Basically I spent an hour debugging some code and at least part of it was because `root + filename` had to be `root/ + filename`, and I'm looking to avoid that in the future.

Original source

Related problems