Results 1 to 4 of 4

Thread: Altering QProcess environment

  1. #1
    Join Date
    Nov 2010
    Posts
    27
    Thanks
    4
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Altering QProcess environment

    Hi guys,

    I have to start ffmpeg from within my program, under Os X. It's installed via macports, so the executable file is in /opt/local/bin/ffmpeg. I'm trying to do this:

    Qt Code:
    1. QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
    2. env.insert("PATH", env.value("PATH") + ":/opt/local/bin");
    3. env.insert("PATH", env.value("PATH") + ":/opt/local/sbin");
    4. this->ffmpegProcess.setProcessEnvironment(env);
    To copy to clipboard, switch view to plain text mode 

    After this I print the environment variables of the process with:

    Qt Code:
    1. QStringList environment = ffmpegProcess.processEnvironment().toStringList();
    2. for(int i=0; i < environment.size(); i++){
    3. std::cout << environment.at(i).toLocal8Bit().constData() << std::endl;
    4. }
    To copy to clipboard, switch view to plain text mode 

    and in effect, I obtain:

    Qt Code:
    1. QTDIR=/usr/local/Qt4.7
    2. PATH=/Developer/Tools/Qt:/usr/bin:/bin:/usr/sbin:/sbin:/opt/local/bin:/opt/local/sbin
    3. TMPDIR=/var/folders/Do/DoA9CZUOFWa0g8wPOe-FYk+++TI/-Tmp-/
    4. etc...
    To copy to clipboard, switch view to plain text mode 

    So, now the PATH is ok, but if I try to start ffmpeg WITHOUT prepending "/opt/local/bin/" it doesn't work.

    Any suggestion?
    Thx in advance

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    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: Altering QProcess environment

    It's not how it works. You need to alter your own environment (qputenv) to make it possible that YOUR application can find some other application in its path. The environment you set for the process becomes effective only when the process is already being (successfully) launched.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. The following user says thank you to wysota for this useful post:

    shaolin (2nd February 2011)

  4. #3
    Join Date
    Nov 2010
    Posts
    27
    Thanks
    4
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Altering QProcess environment

    So to set the PATH variable, for example, I should use qputenv(). Can I use

    Qt Code:
    1. QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
    To copy to clipboard, switch view to plain text mode 

    as in the previous code to get the existing PATH variable, or should I use qgetenv()?

  5. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    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: Altering QProcess environment

    You can do either. Using qgetenv/qputenv is probably simpler as you only want to retrieve one variable.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  6. The following user says thank you to wysota for this useful post:

    shaolin (2nd February 2011)

Similar Threads

  1. Replies: 0
    Last Post: 24th November 2010, 11:11
  2. Replies: 0
    Last Post: 26th August 2010, 10:44
  3. Replies: 0
    Last Post: 1st August 2010, 08:20
  4. Replies: 5
    Last Post: 5th September 2009, 06:34
  5. does qt 4.5.1 have the app environment like qpe?
    By alexcuiCN in forum Installation and Deployment
    Replies: 0
    Last Post: 6th May 2009, 10:21

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.