views:

313

answers:

3

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.

+2  A: 

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

ChristopheD
But _only_ if the `~` is at the beginning.
Georg
You should ensure that it's only done when the ~ is at the start of the path and followed by a path separator. There's also the issue of paths like "~foo/myfile" which should expand to myfile under foo's home. Not sure how easy that would be to handle outside of a *nix environment where it's trivial to query another user's home directory.
jamessan
+1  A: 

I think that the absolutePath (http://qt.nokia.com/doc/4.6/qdir.html#absolutePath) is the way to do it.

e8johan
+1  A: 

Look at the class QDesktopServices:

http://doc.trolltech.com/qtextended4.4/qdesktopservices.html#StandardLocation-enum

Klathzazt