Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I automatically detect a proxy?

Tags:

qt

For one of my projects, I made a QWebView. Everything is working fine, but when I use it at school, I get an error because the proxy is not defined. How would I make it possible to auto detect the proxy, like in Firefox and IE?

I've found this in QNetworkProxyFactory:

setUseSystemConfiguration(bool enable)

But I can't find how to use it.

like image 274
Moustachauve Avatar asked Mar 02 '12 00:03

Moustachauve


People also ask

How do I turn on Auto Proxy Discovery?

Select the proxy you want to configure, then enter the settings on the right. Configure proxy server settings automatically: Select Auto Proxy Discovery. Use a proxy auto-configuration (PAC) file: Select Automatic Proxy Configuration, then enter the address of the PAC file in the URL field.


2 Answers

Since setUseSystemConfiguration is a static method, the following might do what you need:

QNetworkProxyFactory::setUseSystemConfiguration(true);
like image 137
Greg Hewgill Avatar answered Sep 28 '22 04:09

Greg Hewgill


Here is a working example of using the system defined proxy:

QNetworkProxyQuery npq(QUrl("http://www.google.com"));
QList<QNetworkProxy> listOfProxies = QNetworkProxyFactory::systemProxyForQuery(npq);
if (listOfProxies.size())
    QNetworkProxy::setApplicationProxy(listOfProxies[0]);
like image 34
Chris Browet Avatar answered Sep 28 '22 03:09

Chris Browet