1

I'm trying to figure out how to set environment variables to the startDetached function of QProcess in Linux. I did a google and found out that this is a QT Bug and people have suggested workarounds on how to start a detached process and I could see some code to override the startDetached function in Windows set variables to detached qprocess

Could someone please post the code for how this needs to be done in Unix Systems. Thanks!!

Community
  • 1
  • 1
sundar
  • 456
  • 2
  • 7
  • 19
  • Why use Qt for this task? Why not just C library execXX, spawnXX? – Matt Feb 27 '15 at 06:39
  • @user4419802 Thanks for your reply. I'm writing a Qt application and I've used QProcess start() function at a lot of places to start external applications. But for some reason startDetached() function does not take env variables and I need a workaround for this using QProcess itself. – sundar Feb 27 '15 at 07:44

1 Answers1

4

As child process inherits the environment from the parent, I think that the easiest workaround is to save/modify/restore own environment using qgetenv() and qputenv() before and after QProcess::startDetached() call.

Matt
  • 13,674
  • 1
  • 18
  • 27