2

I want to save a QImage in the user's home, I use ~/ but save() seems to not appreciate and return false without any message... So

img->save("~/pict.jpg");

is not working and I'm looking for a glitch...

Thomas Ayoub
  • 29,063
  • 15
  • 95
  • 142
  • Is the missing closing quote in the code as well? It should be `save("~/pict.jpg");` – slaphappy May 31 '13 at 15:10
  • Is the `QImage::save` working when you specify another location? i.e. you've verified it is actually working and that the ~ that's the issue? – Matthew May 31 '13 at 15:14
  • It works well with "./pict.jpg" so I guess ~ is guilty – Thomas Ayoub May 31 '13 at 15:15
  • @VBB ok good because sometimes it can be the JPG plugin isn't installed correctly which can cause `QImage::save` to return false since the format type isn't supported. That doesn't seem to be the case here. :) – Matthew May 31 '13 at 15:15
  • @LucTouraille you're right, I might was looking with the wrong keywords – Thomas Ayoub May 31 '13 at 15:20

1 Answers1

3

~ is interpreted by the Shell, not by the operating system (or the C library, or the Qt library).

You need to get the user's home directory through getenv("HOME"), for instance. See also How can I find the user's home dir in a cross platform manner, using C++?

With Qt, you can use QDir::homepath to retrieve the user's home directory in a platform independent way.

Community
  • 1
  • 1
Andreas Fester
  • 36,091
  • 7
  • 95
  • 123