Results 1 to 5 of 5

Thread: System environment variable

  1. #1
    Join Date
    Oct 2006
    Posts
    8
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Question System environment variable

    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.
    Qt Code:
    1. QTranslator translator;
    2. translator.load(":/translations/assistant_ca.qm");
    3. a.installTranslator(&translator);
    To copy to clipboard, switch view to plain text mode 

    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.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: System environment variable

    Have you tried setenv()?

  3. #3
    Join Date
    Oct 2006
    Posts
    8
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: System environment variable

    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.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: System environment variable

    No, I mean using setenv() function call present in stdlib.

  5. #5
    Join Date
    Oct 2006
    Posts
    8
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: System environment variable

    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.

Similar Threads

  1. Problen with add system environment.
    By Flake in forum Qt Programming
    Replies: 4
    Last Post: 6th September 2007, 15:12
  2. Environment variable
    By Pragya in forum Qt Programming
    Replies: 2
    Last Post: 25th May 2007, 14:02
  3. Qt Cryptographic Architecture
    By vermarajeev in forum Qt Programming
    Replies: 6
    Last Post: 9th February 2007, 14:15

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.