Qt:展开〜到主目录 [英] Qt: Expand ~ to home-directory

查看:104
本文介绍了Qt:展开〜到主目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Qt是否具有任何独立于平台的功能来接受〜/myfile"之类的路径?

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

我了解 wordexp ,但是使用平台,独立包装器.

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

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

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.

推荐答案

您可能只是将波浪号替换为QDir::homePath()的结果?参考此处.

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

这篇关于Qt:展开〜到主目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆