Search code examples
qtqt4proxyqwebviewqnetworkaccessmanager

How do I manage proxies with QT QWebView


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.


Solution

  • 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.