views:

43

answers:

2

I need a similar to .NET method for safely combining path parts without worrying for platform specifics of the path separator.

Is there such class and method in QT4?

Something like:

QPath::Combine
+1  A: 

You may use the static methods QDir::fromNativeSeparators and QDir::toNativeSeparators and then use / everywhere when manipulating the path.

Ivo
This may do the trick but Path.Combine has the trick to also ensure that you have not forgotten the trailing path delimiter when combining Path.Combine("c://test_folder", "filename.txt")Is there such safe path combining technique in QT?
Gad D Lord
Have a look at `QDir` and http://stackoverflow.com/questions/740423/qt-class-for-handling-file-paths .
Ivo
+1  A: 

I don't know of anything exactly like that, but you can get close by using QDir::cd():

QDir path("base_path");
path.cd("subdir");

Unfortunately, I think that only works for directories, not files. For files, you could use QDir::filePath():

QDir path("base_path");
QString file_path = path.filePath("file.txt");
Caleb Huitt - cjhuitt