×
Namespaces

Variants
Actions
(Difference between revisions)

Add Http Proxy support to existing application using QNetworkProxy

From Nokia Developer Wiki
Jump to: navigation, search
andreagrandi (Talk | contribs)
(Andreagrandi -)
 
hamishwillee (Talk | contribs)
m (Hamishwillee - Tidy categories. Add abstract)
Line 1: Line 1:
[[Category:Qt]][[Category:Connectivity]][[Category:Networking]][[Category:Web]][[Category:Symbian]][[Category:MeeGo Harmattan]][[Category:Code Examples]]
+
[[Category:Qt]][[Category:Networking]][[Category:Symbian]][[Category:MeeGo Harmattan]][[Category:Code Examples]][[Category:HTTP]]
 +
{{Abstract|This article shows how to add proxy support at an application level using {{Qapiname|QNetworkProxy}}.}}
 +
 
 
== Introduction ==
 
== Introduction ==
  
Line 6: Line 8:
 
== Idea and implementation ==
 
== Idea and implementation ==
  
You just need to insert this sample code in your '''main.cpp''' (please insert it right before return a.exec();) in the '''main(...)''' method.
+
You just need to insert this sample code in your '''main.cpp''' (please insert it right before return {{Icode|a.exec();}}) in the {{Icode|main(...)}} method.
Of course in this way the proxy settings will be hardcoded, but you can always read/save them from a configuration file, using the '''QSettings''' class.
+
Of course in this way the proxy settings will be hardcoded, but you can always read/save them from a configuration file, using the {{Qapiname|QSettings}} class.
  
 
<code cpp>
 
<code cpp>

Revision as of 03:14, 2 July 2012

This article shows how to add proxy support at an application level using QNetworkProxy.

Introduction

Suppose you have an existing Qt application that makes use of QtNetwork classes. Qt let you specify a proxy for every connection you create, but there is simple way to set global proxy settings so the whole application will use those settings for any connection it will use.

Idea and implementation

You just need to insert this sample code in your main.cpp (please insert it right before return a.exec();) in the main(...) method. Of course in this way the proxy settings will be hardcoded, but you can always read/save them from a configuration file, using the QSettings class.

QNetworkProxy proxy;
proxy.setType(QNetworkProxy::HttpProxy);
proxy.setHostName("proxy.example.com");
proxy.setPort(1080);
proxy.setUser("username");
proxy.setPassword("password");
QNetworkProxy::setApplicationProxy(proxy);
102 page views in the last 30 days.
×