问题
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