简体   繁体   English

如何使用Qt获取系统代理?

[英]How do I get the system proxy using Qt?

I have the following code that I am trying to extract the systems proxy settings from: 我尝试从以下代码中提取系统代理设置:

QList<QNetworkProxy> listOfProxies = QNetworkProxyFactory::systemProxyForQuery();
foreach ( QNetworkProxy loopItem, listOfProxies ) {
    qDebug() << "proxyUsed:" << loopItem.hostName();
}

I only get one item back and with a blank host name. 我只得到一件物品,主机名空白。 Any ideas what I am missing? 有什么想法我想念的吗?

By putting: 通过输入:

QNetworkProxyQuery npq(QUrl("http://www.google.com"));
QList<QNetworkProxy> listOfProxies = QNetworkProxyFactory::systemProxyForQuery(npq);

I appear get the proxy out. 我似乎得到代理。

QNetworkProxyQuery npq(QUrl( QLatin1String (" http://www.google.com "))); QNetworkProxyQuery npq(QUrl( QLatin1String (“ http://www.google.com ”))));

Don't forget to use QLatin1String :) 不要忘了使用QLatin1String :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM