使用Qt构建FS路径的跨平台方法 [英] Cross-platform way of constructing an FS path with Qt
问题描述
可能重复:
Qt相当于PathAppend?
Python的 os.path.join
?
的类比长篇故事:我需要添加一个相对路径到应用程序目录, QCoreApplication :: applicationDirPath()
以正确的方式(TM),使代码不依赖于文件系统目录分隔符。
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.
只是加入QStrings并使用/作为分隔符好的解决方案?
Is merely joining QStrings and using "/" as the separator a good solution?
推荐答案
p>您可以直接使用/,也可以使用 QDir :: separator()
。但一般来说,请使用 QDir
为此(它将/翻译为您的平台特定路径分隔符)。
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).
这篇关于使用Qt构建FS路径的跨平台方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!