开发者

Cross-platform way of constructing an FS path with Qt [duplicate]

开发者 https://www.devze.com 2023-01-05 20:21 出处:网络
This question already has an answer here: 开发者_如何学运维Closed 10 years ago. Possible Duplicate:
This question already has an answer here: 开发者_如何学运维 Closed 10 years ago.

Possible Duplicate:

Qt equivalent of PathAppend?

Short story: does Qt 4 have an analog of Python's os.path.join?

Long story: I need to add a relative path to the application directory, QCoreApplication::applicationDirPath() in the Right Way (TM), so that the code doesn't depend on the file system directory separator character.

Is merely joining QStrings and using "/" as the separator a good solution?


You can either use "/" directly or use QDir::separator(). But in general use a QDir for this (which translates "/" to the platform specific path separator for you).


From Qt 4.6 QDir documentation,

Qt uses "/" as a universal directory separator in the same way that "/" is used as a path separator in URLs. If you always use "/" as a directory separator, Qt will translate your paths to conform to the underlying operating system.

So, I guess QDir will be helpful for you.


Just use "/" when staying in the Qt world. To convert the path for non-Qt classes and functions etc., use QDir::toNativeSeparators( path ).

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号