March 27, 2012

Ashish Mittal Ashish Mittal
Ant Farmer
151 posts

[SOLVED] Can we set specific Network proxy for QWebView

 

I am having one application where I am creating multiple QWebView objects.
Since each QWebView object is loading different URL , and my network admin wanted to route the specific url through some proxy.
I have one function QNetworkProxy::setApplicationProxy(), which will set the proxy for the entire app, i.e. all QWebView will use that proxy , but I wanted to use different proxy for different QWebView.

Please advice how can we achieve this.
Please help it is very urgent!!!!!

5 replies

March 27, 2012

leon.anavi leon.anavi
Mad Scientist
1045 posts

I think that the official Qt documentation offers a solution for your request [qt-project.org]:

An alternative to setting an application wide proxy is to specify the proxy for individual sockets using QAbstractSocket::setProxy() and QTcpServer::setProxy(). In this way, it is possible to disable the use of a proxy for specific sockets using the following code:

  1.  serverSocket->setProxy(QNetworkProxy::NoProxy);

 Signature 

http://anavi.org/

March 27, 2012

Ashish Mittal Ashish Mittal
Ant Farmer
151 posts

Thanks for your suggestion , but I am not using any QTCPSocket/QAbstractSocket/QTcpServer at all.
I am just using QWebview to load my url. and we can’t call this function(setProxy) on QWebView.

so probably this is not the way to achieve this.
Please share if you have any other thought

March 27, 2012

leon.anavi leon.anavi
Mad Scientist
1045 posts

Have you seen this thread at stackoverflow [stackoverflow.com]?

It highlights the documentation about QWebPage [qt-project.org] and method setNetworkAccessManager [qt-project.org]:

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.

The recommended solution at stackoverflow.com [stackoverflow.com] to create QNetworkAccessManager, set up a proxy and then to pass it to the web page seems reasonable.

 Signature 

http://anavi.org/

March 28, 2012

Ashish Mittal Ashish Mittal
Ant Farmer
151 posts

Thanks a lot leon!!!!!!!!!!!!

You made my life really cool.
I am being able to set the different proxy for different Qwebview inside a single application.
your solution simply rockzz!!!!!!!!

March 28, 2012

leon.anavi leon.anavi
Mad Scientist
1045 posts

Ashish Mittal wrote:
Thanks a lot leon!!!!!!!!!!!!

You made my life really cool.
I am being able to set the different proxy for different Qwebview inside a single application.
your solution simply rockzz!!!!!!!!

You are welcome :) I am glad that the issue was solved but please note that I got the idea from a thread at stackoverflow.com [stackoverflow.com].

 Signature 

http://anavi.org/

 
  ‹‹ How to write descriptions for elements in the interface window      QAbstractProxyModel , mapToSource() and mapFromSource() ››

You must log in to post a reply. Not a member yet? Register here!