Qt:展开 ~ 到主目录

发布于 2024-08-12 17:51:25 字数 369 浏览 4 评论 0原文

Qt 是否有任何独立于平台的功能来接受像“~/myfile”这样的路径?

我知道 wordexp,但是使用独立于平台的包装器会很好。

编辑:

谢谢大家的回复。 “~/myfile”只是一个例子。我正在寻找的是处理文件路径的功能,就像您可以在命令行上编写的那样。因此,在 Linux 上,它应该接受“~/myfile”、“~otheruser/hisfile”、“$VAR/file”等。在 Windows 上,它应该接受“%HOMEDIR%\myfile”等。

Does Qt have any platform-independent functionality to accept paths like "~/myfile"?

I know about wordexp, but it would be nice with a platform-independent wrapper.

Edit:

Thank you all for the responses. "~/myfile" was just an example. What I am looking for is functionality to handle file-paths as you would be able to write on the command-line. So on Linux, it should accept "~/myfile", "~otheruser/hisfile", "$VAR/file" etc. On Windows, it should accept "%HOMEDIR%\myfile" etc.

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

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

发布评论

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

评论(2

末骤雨初歇 2024-08-19 17:51:25

您可能可以将波形符替换为 QDir::homePath() 的结果?参考此处

You could probably just replace the tilde with the result of QDir::homePath()? Reference here.

何止钟意 2024-08-19 17:51:25

我认为绝对路径 (http://doc.qt.io/qt- 5/qdir.html#absolutePath) 就是这样做的方法。

I think that the absolutePath (http://doc.qt.io/qt-5/qdir.html#absolutePath) is the way to do it.

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