How to get a system proxy using Qt?

I have the following code that I am trying to extract system proxy settings:

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

I get only one item back and with an empty host name. Any ideas what I am missing?

+2
source share
2 answers

Assuming:

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

I get a proxy server.

+5
source

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

Remember to use QLatin1String :)

+1
source

All Articles