Results 1 to 4 of 4

Thread: QProcess setEvironment

  1. #1
    Join Date
    Aug 2012
    Posts
    2
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Default QProcess setEvironment

    My Qt application, which calls ffmpeg, is working great on Linux.

    It works on OS X as long as I launch it from a Terminal, but not if I launch it from the desktop; so obviously from the GUI launcher it's not inheriting the appropriate environment.

    So I'm trying to utilize QProcess systemEnvironment

    The Qt docs gives this Windows-ian example:

    Qt Code:
    1. QProcess process;
    2. QStringList env = QProcess::systemEnvironment();
    3. env << "TMPDIR=C:\\MyApp\\temp"; // Add an environment variable
    4. env.replaceInStrings(QRegExp("^PATH=(.*)", Qt::CaseInsensitive), "PATH=\\1;C:\\Bin");
    5. process.setEnvironment(env);
    6. process.start("myapp");
    To copy to clipboard, switch view to plain text mode 

    Which I assume I would adapt like this:

    Qt Code:
    1. void startProcess()
    2. {
    3. QProcess process;
    4. QStringList env = QProcess::systemEnvironment();
    5. env << ":/usr/local/bin"; // Add the bin dir to PATH
    6. process.setEnvironment(env);
    7. process.start("????");
    To copy to clipboard, switch view to plain text mode 

    My three questions:
    1. I am not sure if I am adding /usr/local/bin to PATH or not. I think I am.
    2. What exactly am I satarting with process.start ? main? mainwindow.cpp ? what is it asking for here?
    3. Also, am I right to be placing that block of code in main.cpp above int main or is there a better place for it.

    Thanks in advance. Qt is amazing so far!

  2. #2
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QProcess setEvironment

    Quote Originally Posted by bagels4ever View Post
    My three questions:
    1. I am not sure if I am adding /usr/local/bin to PATH or not. I think I am.
    No, you are not. I don't see PATH variable in your code.

    Quote Originally Posted by bagels4ever View Post
    2. What exactly am I satarting with process.start ? main? mainwindow.cpp ? what is it asking for here?
    You should run an app, eg app_name.app or app_name.app/Contents/MacOS/app_name.

    Quote Originally Posted by bagels4ever View Post
    3. Also, am I right to be placing that block of code in main.cpp above int main or is there a better place for it.
    It's hard to say what you want.

    Side question: Are you trying to set system variable to run your own app or for running other app?
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  3. #3
    Join Date
    Aug 2012
    Posts
    2
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Default Re: QProcess setEvironment

    OK, it's becoming a bit clearer now.

    I believe I have the code in the correct place and acting, more or less, on the correct funciton.

    Qt Code:
    1. QProcess commandProcess;
    2. QStringList env = QProcess::systemEnvironment();
    3. env << "PATH"; // Add an environment variable
    4. env.replaceInStrings(QRegExp("^PATH=(.*)", Qt::CaseInsensitive), "PATH=$PATH:/usr/local/bin");
    5. commandProcess.setEnvironment(env);
    6. commandProcess.start("ffmpeg", args);
    To copy to clipboard, switch view to plain text mode 

    My only question now, I think, is whether I'm setting the PATH correctly. I'm having trouble using printf's to actually see what the variables are that I'm trying to change.
    Last edited by bagels4ever; 22nd August 2012 at 20:32.

  4. #4
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QProcess setEvironment

    I see.
    You may also want to look at QProcessEnvironment.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

Similar Threads

  1. Replies: 0
    Last Post: 26th August 2010, 10:44
  2. QProcess or something else??
    By zakis in forum Qt Programming
    Replies: 1
    Last Post: 12th January 2010, 19:33
  3. QProcess inside QProcess
    By bunjee in forum Qt Programming
    Replies: 7
    Last Post: 4th December 2008, 00:39
  4. help QProcess
    By totosugito in forum Qt Programming
    Replies: 3
    Last Post: 31st January 2008, 14:42
  5. QProcess again ..
    By cmeliak in forum Qt Programming
    Replies: 13
    Last Post: 24th May 2006, 20:56

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
  •  
Qt is a trademark of The Qt Company.