0

I've found this Topic : Set Environment Variables for startDetached() QProcess. Which explains how to solve the Environment variables with Qt 4 by overloading the startDetached() function.

I'm encountering the same problem with startDetached(), meaning I can't set an environment variable for my newly spawn process with setEnv().

However, I'm working with Qt 4.8.5 and the post is now more than 3 years old, is there a way to set an environment variables for a detached process in Qt nowadays with Qt 4.8.5 ?

I'm a bit stuck, because I don't know how to overload a qProcess function, and I really want to find an easier solution if possible ...

Do you have an easier solution ? Or can you explain me how to apply the overloading one ?

Community
  • 1
  • 1
Xaltar
  • 1,688
  • 14
  • 22

1 Answers1

0

I think what you're looking for is QProcessEnvironment, which is a class that generates name-value pairs of your environment variables to pass to a QProcess.

You can use it in the following manner:

QProcessEnvironment environment = QProcessEnvironment::systenEnvironment();
QProcess process;
process.setProcessEnvironment(environment);

Note: the above code is untested and non-compiled, but should be fairly close to the use case.

Tyler Jandreau
  • 4,245
  • 1
  • 22
  • 47
  • Are you 100% sure that I can use a startDetached() process with that ? For exemple, here : http://stackoverflow.com/questions/21184986/change-path-environment-variable-for-cmd-exe-with-qprocessenvironment the OP modifyed the original Qt code to make it work ... – Xaltar Mar 17 '14 at 12:55
  • Yep, pretty sure. In that post, the OP is attempting to modify the `path` variable. If you have your environment set up correctly, you shouldn't need to do this. I've done this process before and it's worked. If it doesn't work, comment back and we'll work on a solution together. – Tyler Jandreau Mar 17 '14 at 12:59
  • I've tryed this : http://ideone.com/rF4bPu and http://ideone.com/9cAWaB, but it doesn't see the outputting environment variable ... But it says that my var is not found ... – Xaltar Mar 17 '14 at 17:14