Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Problem with QDir::homePath()
Forum Updated to NodeBB v4.3 + New Features

Problem with QDir::homePath()

Scheduled Pinned Locked Moved General and Desktop
8 Posts 4 Posters 7.8k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    lemzwerg
    wrote on last edited by
    #1

    [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
    
    1 Reply Last reply
    0
    • A Offline
      A Offline
      andre
      wrote on last edited by
      #2

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

      1 Reply Last reply
      0
      • L Offline
        L Offline
        lemzwerg
        wrote on last edited by
        #3

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

        1 Reply Last reply
        0
        • A Offline
          A Offline
          andre
          wrote on last edited by
          #4

          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.

          1 Reply Last reply
          0
          • L Offline
            L Offline
            lgeyer
            wrote on last edited by
            #5

            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.

            1 Reply Last reply
            0
            • G Offline
              G Offline
              goetz
              wrote on last edited by
              #6

              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");
              @

              http://www.catb.org/~esr/faqs/smart-questions.html

              1 Reply Last reply
              0
              • A Offline
                A Offline
                andre
                wrote on last edited by
                #7

                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]

                1 Reply Last reply
                0
                • L Offline
                  L Offline
                  lemzwerg
                  wrote on last edited by
                  #8

                  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.

                  1 Reply Last reply
                  0

                  • Login

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved