为startDetached() QProcess设置环境变量
在 Qt4 中,有 QProcess::setProcessEnvironment() 用于为新生成的进程设置 Env 变量。
但是,QProcess::startDetached() 是静态成员函数,因此 setProcessEnvironment() 不适用。如何在 Qt 中为独立进程设置环境变量?
In Qt4, there is QProcess::setProcessEnvironment() for setting Env variables for the newly spawn process.
However, QProcess::startDetached() is a static member function, so setProcessEnvironment() doesn't apply. How does one set Env variables for a detached process in Qt?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这是一个已知的老错误: http://bugreports.qt-project.org/browse/ QTBUG-2284。您需要重载
startDetached
函数来支持您自己的环境。查看 Qt 源代码以了解如何执行此操作: http://code.qt.io/cgit/qt/qtbase.git/tree/src/corelib/io?h=5.5(qprocess*
文件)。It is a known old bug: http://bugreports.qt-project.org/browse/QTBUG-2284. You need to overload
startDetached
function to support your own environment. Take a look at Qt sources to see how to do that: http://code.qt.io/cgit/qt/qtbase.git/tree/src/corelib/io?h=5.5 (qprocess*
files).此行为已在
Qt 5.10.0
中修复。然而,调用的顺序似乎很重要。以下示例有效:而这无效:
This behaviour has been fixed in
Qt 5.10.0
. However, the order of calls seems to be important. The following example works:while this does not work:
现在使用Qt5.5,遇到这个问题。
在Win7下,使用下面的代码,在父进程中设置环境,看来子进程继承了环境。不确定,但它对我的情况有效。
希望有更好的解决方案
Using Qt5.5 now, Run into this problem.
Under Win7, Used code below, Set environment in father process, It seems that sub process inherit the environment. Not for sure, but it worked in my case.
Hope there is better solutions