如何在Linux上使用QProcessEnvironment设置代理地址? [英] How to set Proxy Address using QProcessEnvironment on Linux?
问题描述
我遇到一个简单的问题在Qt。我想使用Qt设置代理地址。设置代理地址的命令
I am stuck with a simple issue in Qt. I want set proxy address using Qt. The command to set proxy address
export http_proxy=http://wwgw.abcd.com:8080
工作正常,如果由终端手动传递。但如果使用QProcess运行相同的命令,它会失败,而不设置代理。甚至,我尝试QProcessEnvironment作为
works fine if passed by a terminal manually. but If the same command is run using QProcess, it fails without setting proxy. Even, I tried with QProcessEnvironment as
QProcess process_setupProxyServerUrl;
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
QString cmd = "http://wwgw.abcd.com:8080";
env.insert("HTTP_PROXY", cmd);
process_setupProxyServerUrl.setProcessEnvironment(env);
但这也无法设置代理地址。 QProcessEnvironment对我来说是新的。
But this also fails in setting up proxy address. QProcessEnvironment is new for me. So may be i might be using it in wrong way.
在我的应用程序中,我需要根据用户的选择更改代理地址(在运行时)。
In my application, I need to change the proxy address according to users choice (at run time).
使用Qt的任何方式都会有帮助。请提供一些建议/建议以解决此问题。
Any way using Qt would be helpfull. Please provide some suggestions/ideas to resolve this issue.
推荐答案
尝试类似
QProcess process_setupProxyServerUrl;
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
env.insert("HTTP_PROXY", "http://wwgw.abcd.com:8080");
process_setupProxyServerUrl.setProcessEnvironment(env);
为什么使用导出?这只是一个可执行文件,而不是环境键
Why did you use export ? This is just an executable, not the environment key
这篇关于如何在Linux上使用QProcessEnvironment设置代理地址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!