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. Environment variables on Windows

Environment variables on Windows

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 1.9k 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.
  • bart_janssensB Offline
    bart_janssensB Offline
    bart_janssens
    wrote on last edited by
    #1

    Hi all,

    I just ran into a weird problem with environment variables on Windows:

    • QProcessEnvironment::systemEnvironment().value("VARNAME") shows the correct value
    • qgetenv("VARNAME") shows up empty

    The variable in question was set using SetEnvironmentVariableW on application startup before calling the QApplication constructor. Looking at the qgetenv implementation on Qt 5.6, it seems to use some kind of cache for the environment variables (in the file src\corelib\kernel\qfunctions_fake_env_p.h), does this cache somehow get initialized before creating the QApplication?

    Chees,

    Bart

    1 Reply Last reply
    0
    • hskoglundH Offline
      hskoglundH Offline
      hskoglund
      wrote on last edited by hskoglund
      #2

      Hi, Qt has no cache for normal Windows (that fake API stuff you see is just for pretending there's an environment for WinCE Qt apps).

      I think instead you are seeing an old Windows gotcha , what I mean, getenv()/putenv() works nice together but do not play well with SetEnvironmentVariable().

      Also, putenv()/getenv() works fine regardless of QApplication has been constructed or not :-)

      Edit: actually you could say there's a cache, or copy of the environment variables stored in the process, which getenv()/putenv() uses but SetEnvironmentVariable() does not. It's part of the design of Windows apps.

      1 Reply Last reply
      3
      • bart_janssensB Offline
        bart_janssensB Offline
        bart_janssens
        wrote on last edited by
        #3

        Allright, thanks a lot, that explains this behavior.

        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