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. How to set windows system path using Qt api
Forum Update on Monday, May 27th 2025

How to set windows system path using Qt api

Scheduled Pinned Locked Moved General and Desktop
6 Posts 4 Posters 5.8k Views
  • 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.
  • P Offline
    P Offline
    prbiswal
    wrote on 14 Oct 2011, 09:34 last edited by
    #1

    Hi,

    I want to add a the bin path of installed JDK to window's system variable's path from qt application.
    May i know if there are any apis to edit window systme variable's path. If anybody knows plz share code example.

    regards,
    Pradeep

    Regards,
    Pradeep

    1 Reply Last reply
    0
    • G Offline
      G Offline
      giesbert
      wrote on 14 Oct 2011, 09:45 last edited by
      #2

      no, there are not

      you can change the path of your app by using putenv.
      The system environment isv stored in the registry and from there given to each top most process. From there on, you have no chance from outside to change it, only from inside of the process.

      Nokia Certified Qt Specialist.
      Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

      1 Reply Last reply
      0
      • P Offline
        P Offline
        prbiswal
        wrote on 14 Oct 2011, 10:08 last edited by
        #3

        Thanks for the reply.

        Just tried the below code to set jre path from my qt app.

        putenv("PATH=C:\Apps\Java\jre6\bin");

        then i saw in the system variable, it did not add to the path variable. Any idea how to do it?

        regards,
        Pradeep

        Regards,
        Pradeep

        1 Reply Last reply
        0
        • F Offline
          F Offline
          fluca1978
          wrote on 14 Oct 2011, 10:27 last edited by
          #4

          could be:
          @putenv(“PATH=%PATH%;C:\Apps\Java\jre6\bin”); @

          1 Reply Last reply
          0
          • P Offline
            P Offline
            prbiswal
            wrote on 14 Oct 2011, 10:46 last edited by
            #5

            i tried the below code

            putenv("PATH=%PATH%;C:\Apps\Java\jre6\bin");
            QString path = getenv("PATH");

            This code did not append to the system var path :(
            but while debugging i could see getenv returns the string %PATH%;C:\Apps\Java\jre6\bin.

            Regards,
            Pradeep

            1 Reply Last reply
            0
            • L Offline
              L Offline
              lgeyer
              wrote on 14 Oct 2011, 10:49 last edited by
              #6

              Well, this is not how environments work.

              There is one inital system environment (stored in the registry on Windows) which is passed to each created process by the kernel. If a process now spawns another process (which is true for the majority of the processes, userland processes are not spawn by the kernel, but for example by Explorer.exe instead) the environment is passed to the spawned process. This means that a process can always alter its own environment (which gets passed to processes it spawns).

              If you want to change the environment for other processes you will have to change the system environment and restart all processes (log off and log on on Windows).

              In fact Windows provides another method by broadcasting WM_SETTINGCHANGE which enables applications aware of that message to re-initialize their environment (which should be true for at least the Windows Explorer, Program Manager and Task Manager).

              1 Reply Last reply
              0

              1/6

              14 Oct 2011, 09:34

              • Login

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