Search code examples
qtqtcoreqprocess

QProcess Set Environment Variables for startDetached


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!!


Solution

  • 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.