January 19, 2012

lemzwerg lemzwerg
Lab Rat
13 posts

problem with QDir::homePath()

 

[GNU/Linux, Qt 4.8]

I have

HOME=/home/wl

in my environment, but

QDir::homePath()

returns “/” instead of “/home/wl”.

How comes? For debugging, I’ve also used getenv() at the very same place in the code, and it correctly returns “/home/wl”.

Werner

7 replies

January 19, 2012

Andre Andre
Area 51 Engineer
6031 posts

Hmmm… weird.
Could you try what QDesktopServices::storageLocation(QDesktopServices::HomeLocation) returns?

 Signature 

Looking for Qt developers to join our team @ i-Optics: https://qt-project.org/forums/viewthread/25393/

January 19, 2012

lemzwerg lemzwerg
Lab Rat
13 posts

It also returns “/”.

Maybe a build issue? I’m running openSuSE factory; the installed Qt package is libqt4-4.8.0-245.2 (from obs://build.opensuse.org/KDE).

January 19, 2012

Andre Andre
Area 51 Engineer
6031 posts

I don’t know, sorry. According to the docs, it should return HOME from the environment. No idea why it doesn’t in your case.

 Signature 

Looking for Qt developers to join our team @ i-Optics: https://qt-project.org/forums/viewthread/25393/

January 19, 2012

Lukas Geyer Lukas Geyer
Gene Splicer
2074 posts

Have you tried stepping through QDir::homePath() to find out why it returns / ? As far as I know it is the fallback behaviour when the home directory couldn’t be read for whatever reason.

January 19, 2012

Volker Volker
Robot Herder
5428 posts

The homePath is extracted from the HOME environment variable. If that is empty, the filesystem root is used:

qfilesystemengine_unix.cpp:

  1. QString QFileSystemEngine::homePath()
  2. {
  3.     QString home = QFile::decodeName(qgetenv("HOME"));
  4.     if (home.isNull())
  5.         home = rootPath();
  6.     return QDir::cleanPath(home);
  7. }

So it seems your HOME env variable got lost during application startup. You should check that with

  1. qDebug() << qgetenv("HOME");

January 19, 2012

Andre Andre
Area 51 Engineer
6031 posts

I figured, he already tried that:

lemzwerg wrote:
[GNU/Linux, Qt 4.8] (…) For debugging, I’ve also used getenv() at the very same place in the code, and it correctly returns “/home/wl”.
 Signature 

Looking for Qt developers to join our team @ i-Optics: https://qt-project.org/forums/viewthread/25393/

January 19, 2012

lemzwerg lemzwerg
Lab Rat
13 posts

My mistake. I interpreted UTF-16 as UTF-8, using `.constData()’ instead of `qPrintable(…)’. Everything’s fine now, and thanks to all of you for your help.

 
  ‹‹ Kubuntu 10.11 and OpenGL      QIODevice: Trouble replicating writeBlock behaviour ››

You must log in to post a reply. Not a member yet? Register here!