用Qt构建FS路径的跨平台方式

发布于 2024-09-08 15:42:14 字数 381 浏览 1 评论 0原文

可能的重复:
Qt 相当于 PathAppend?

短篇故事:Qt 4 是否有 Python 操作系统的类似版本.path.join?

长话短说:我需要以正确的方式(TM)添加应用程序目录的相对路径QCoreApplication::applicationDirPath(),以便代码不依赖于文件系统目录分隔符特点。

仅仅加入 QStrings 并使用“/”作为分隔符是一个好的解决方案吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

无可置疑 2024-09-15 15:42:14

您可以直接使用“/”,也可以使用 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).

悸初 2024-09-15 15:42:14

从 Qt 4.6 QDir 文档,

Qt 使用“/”作为通用目录分隔符,就像“/”在 URL 中用作路径分隔符一样。如果您始终使用“/”作为目录分隔符,Qt 将转换您的路径以符合底层操作系统。

因此,我想 QDir 对您会有帮助。

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.

那片花海 2024-09-15 15:42:14

留在 Qt 世界时只需使用“/”。
要转换非 Qt 类和函数等的路径,请使用 QDir::toNativeSeparators( path )。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文