Search code examples
c++qtgdal

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


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.


Solution

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