How to set Proxy Address using QProcessEnvironment

2019-07-25 14:00发布

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.

标签: c++ linux qt qt4
1条回答
够拽才男人
2楼-- · 2019-07-25 14:29

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

查看更多
登录 后发表回答