×
Namespaces

Variants
Actions
(Difference between revisions)

Add Http Proxy support to existing application using QNetworkProxy

From Nokia Developer Wiki
Jump to: navigation, search
hamishwillee (Talk | contribs)
m (Hamishwillee - Tidy categories. Add abstract)
hamishwillee (Talk | contribs)
m (Text replace - "<code cpp>" to "<code cpp-qt>")
 
(One intermediate revision by one user not shown)
Line 1: Line 1:
[[Category:Qt]][[Category:Networking]][[Category:Symbian]][[Category:MeeGo Harmattan]][[Category:Code Examples]][[Category:HTTP]]
+
{{ArticleMetaData <!-- v1.2 -->
 +
|sourcecode= <!-- Link to example source code e.g. [[Media:The Code Example ZIP.zip]] -->
 +
|installfile= <!-- Link to installation file (e.g. [[Media:The Installation File.sis]]) -->
 +
|devices= <!-- Devices tested against - e.g. ''devices=Nokia 6131 NFC, Nokia C7-00'') -->
 +
|sdk= <!-- SDK(s) built and tested against (e.g. [http://linktosdkdownload/ Qt SDK 1.1.4]) -->
 +
|platform= <!-- Compatible platforms - e.g. Symbian^1 and later, Qt 4.6 and later -->
 +
|devicecompatability= <!-- Compatible devices e.g.: All* (must have internal GPS) -->
 +
|dependencies= <!-- Any other/external dependencies e.g.: Google Maps Api v1.0 -->
 +
|signing= <!-- Signing requirements - empty or one of: Self-Signed, DevCert, Manufacturer -->
 +
|capabilities= <!-- Capabilities required by the article/code example (e.g. Location, NetworkServices. -->
 +
|keywords= <!-- APIs, classes and methods (e.g. QSystemScreenSaver, QList, CBase -->
 +
|language= <!-- Language category code for non-English topics - e.g. Lang-Chinese -->
 +
|translated-by= <!-- [[User:XXXX]] -->
 +
|translated-from-title= <!-- Title only -->
 +
|translated-from-id= <!-- Id of translated revision -->
 +
|review-by= <!-- After re-review: [[User:username]] -->
 +
|review-timestamp= <!-- After re-review: YYYYMMDD -->
 +
|update-by= <!-- After significant update: [[User:username]]-->
 +
|update-timestamp= <!-- After significant update: YYYYMMDD -->
 +
|creationdate= 20120627
 +
|author= [[User:Andreagrandi]]
 +
}}
 +
[[Category:Qt]][[Category:Networking]][[Category:Symbian]][[Category:MeeGo Harmattan]][[Category:Code Snippet]][[Category:HTTP]]
 
{{Abstract|This article shows how to add proxy support at an application level using {{Qapiname|QNetworkProxy}}.}}
 
{{Abstract|This article shows how to add proxy support at an application level using {{Qapiname|QNetworkProxy}}.}}
  
Line 11: Line 33:
 
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.
 
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-qt>
 
QNetworkProxy proxy;
 
QNetworkProxy proxy;
 
proxy.setType(QNetworkProxy::HttpProxy);
 
proxy.setType(QNetworkProxy::HttpProxy);

Latest revision as of 04:15, 11 October 2012

Article Metadata
Compatibility
Platform(s):
Symbian
Article
Created: andreagrandi (27 Jun 2012)
Last edited: hamishwillee (11 Oct 2012)

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

[edit] 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.

[edit] 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);
This page was last modified on 11 October 2012, at 04:15.
107 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×