Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
How to set windows system path using Qt api
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.
giesbert last edited by
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.
Thanks for the reply.
Just tried the below code to set jre path from my qt app.
then i saw in the system variable, it did not add to the path variable. Any idea how to do it?
fluca1978 last edited by
i tried the below code
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.
lgeyer last edited by
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).