How to set Proxy Address using QProcessEnvironment on Linux?

我们两清 提交于 2019-12-24 08:09:26

问题


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

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);

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

Any way using Qt would be helpfull. Please provide some suggestions/ideas to resolve this issue.


回答1:


Try something like that

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



来源:https://stackoverflow.com/questions/13950755/how-to-set-proxy-address-using-qprocessenvironment-on-linux

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!