PDA

View Full Version : Altering QProcess environment



shaolin
31st January 2011, 12:30
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:



QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
env.insert("PATH", env.value("PATH") + ":/opt/local/bin");
env.insert("PATH", env.value("PATH") + ":/opt/local/sbin");
this->ffmpegProcess.setProcessEnvironment(env);


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



QStringList environment = ffmpegProcess.processEnvironment().toStringList();
for(int i=0; i < environment.size(); i++){
std::cout << environment.at(i).toLocal8Bit().constData() << std::endl;
}


and in effect, I obtain:



QTDIR=/usr/local/Qt4.7
PATH=/Developer/Tools/Qt:/usr/bin:/bin:/usr/sbin:/sbin:/opt/local/bin:/opt/local/sbin
TMPDIR=/var/folders/Do/DoA9CZUOFWa0g8wPOe-FYk+++TI/-Tmp-/
etc...


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

wysota
31st January 2011, 20:14
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.

shaolin
2nd February 2011, 10:57
So to set the PATH variable, for example, I should use qputenv(). Can I use


QProcessEnvironment env = QProcessEnvironment::systemEnvironment();

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

wysota
2nd February 2011, 11:00
You can do either. Using qgetenv/qputenv is probably simpler as you only want to retrieve one variable.