简体   繁体   中英

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

Don't forget to use QLatin1String :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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