4

This is how I change proxy:

QNetworkProxy proxy;
proxy.setType(QNetworkProxy::HttpProxy);
proxy.setHostName("ip");
proxy.setPort(8008);

QNetworkProxy::setApplicationProxy(proxy);

It works properly if I do it before I create WebView. But if I change proxies during life time of QWebView, it simply wont load any site. What's the proper way of changing proxy on fly in QT?

Thanks.

1
  • A note in the doc for QNetworkProxy says " Note: Changes made to currently connected sockets do not take effect. If you need to change a connected socket, you should reconnect it." . Also have you tried webview->page()->networkAccessManager()->setProxy(proxy);
    – Abhijith
    May 20, 2011 at 14:14

1 Answer 1

5

QWebPage::setNetworkAccessManager method documents says that

Note: It is currently not supported to change the network access manager after the QWebPage has used it. The results of doing this are undefined.

So my guess is that once you setup an application wide proxy and once QWebPage is constructed it gets a QNetworkAccessManager and you can not change its proxy settings.

As an alternative to using an application wide proxy, you probably can create a new QNetworkAccessManager and use its QNetworkAccessManager::setProxy() method to to setup a proxy. Then pass this QNetworkAccessManager instance to your web page.

Anyway you need to play with it. I hope this helps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.