So I need to run an non-Qt application lets call it 'App'. The options on which App runs are set via env Vars like export APP_VAR1="1". I implemented a DropDown to make a set of option choices which will need to call several of these export commands. I've failed to do this in Qt. I've been trying to work around it with a setup.sh script which is executed with system(./setup.sh) but it will only set the enviroment variable for the QtApp and not on the system. I've also used an implementation of QProcess but Im not sure if this was properly implemented.
I would be super glad if anyone of you could tell me how to achieve this.
Thanks in advance, tox20
Are you looking for QProcess + QProcessEnvironment ?
I assume you are launching your app from inside a Qt app?
In that case:
Thanks so much guys, just what i was searching for. In fact i already had this thing put into my code but it didn't work out as it closed on start. This is caused by the fact that the memory for an app that you call via QProcess is allocated from the program stack. When the variable goes out of scope, the memory which was taken on the stack is freed. Therefore you need to alloate it in the heap. Here's how i did it.
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
QProcess *proc; // pointer definition proc = new QProcess( this ); // memory allocation from heap, created with parent proc->setProcessEnvironment(env); // set environment variables proc->start("regedit.exe"); // start program
Be are these env vars will not be available once the process is finished/closed.