How to set an environment variable programmatically for the current process in Qt?

StackOverflow https://stackoverflow.com/questions/18238130

  •  24-06-2022
  •  | 
  •  

I use the GDAL. CPLSetConfigOption("GDAL_DATA", "mygdaldir") works, but throws an exception when finishing the app. It is possible to set GDAL_DATA as "global" environment variable but I want to do it programmatically for the current process instead of configure it externally.

Any ways how to set an environment variable for the current process/app itself?

EDIT:

Found the problem: GDAL_DATA pointed to the wrong directory => GDAL fails to unload correctly. Anyway, @Greenflow gives us a fitting answer to my question and even if I don't need his solution I accepted his answer.

有帮助吗?

解决方案

You might want to read the docs for qgetenv and qputenv.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top