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


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



  • 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).



  • 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.



  • 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.



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

    qfilesystemengine_unix.cpp:

    @
    QString QFileSystemEngine::homePath()
    {
    QString home = QFile::decodeName(qgetenv("HOME"));
    if (home.isNull())
    home = rootPath();
    return QDir::cleanPath(home);
    }
    @

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

    @
    qDebug() << qgetenv("HOME");
    @



  • I figured, he already tried that:

    [quote author="lemzwerg" date="1326958147"][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".
    [/quote]



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


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.