×
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 - Bot update - Fix ArticleMetaData)
hamishwillee (Talk | contribs)
m (Text replace - "<code cpp>" to "<code cpp-qt>")
 
Line 33: 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.
106 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.

×