PDA

View Full Version : System environment variable



fahlen
27th November 2007, 17:36
Is there any way to set a system environment variable for the currently running application from within the application itself? I don't intend to change the system environment variables for the entire system, only for my application and for the duration of its execution. You may wonder why I would want to do this. It appears that in order to localize the QAssistantClient, one has to specify the system variable LANG, e.g. LANG=ca. If I then start the assitant with the "-resourceDir" argument specified, it picks up the correct translations.

I have also tried to instead do the following in main.cpp, hoping the QAssistantClient would pick up the translation, but with no luck.


QTranslator translator;
translator.load(":/translations/assistant_ca.qm");
a.installTranslator(&translator);


So, does anyone know how I can set the value of the variable LANG from within my app (for the duration of the execution without affecting the actual system variables)? Or even better, how to make the QAssistantClient pick up a translation without using system environment variables.

Thanks in advance.

wysota
27th November 2007, 17:46
Have you tried setenv()?

fahlen
27th November 2007, 17:58
You mean using "setenv LANG ca" with tsh in Linux? But then I would have to use "export LANG=ca" with bash. And on Windows I'd have to use the command "set", right? Or is there a setenv() method in the Qt libraries? I have tried finding it in the documentation, but I haven't been able to. If possible I'd like to avoid having to do things differentely on different platforms. I also have to make sure it works OK on Mac OS X.

wysota
27th November 2007, 18:02
No, I mean using setenv() function call present in stdlib.

fahlen
27th November 2007, 20:02
Wow, do I feel stupid. I guess I should take the time to investigate the standard c libraries. I have been so focused on looking for the answer in Qt... Thank a lot! Works like a charm.