Viadeo Twitter Google Bookmarks ! Facebook Digg del.icio.us MySpace Yahoo MyWeb Blinklist Netvouz Reddit Simpy StumbleUpon Bookmarks Windows Live Favorites 
Logo Documentation Qt ·  Page d'accueil  ·  Tous les espaces de nom  ·  Toutes les classes  ·  Classes principales  ·  Annotées  ·  Classes groupées  ·  Modules  ·  Fonctions  · 

QNetworkProxy Class Reference
[QtNetwork module]

The QNetworkProxy class provides a network layer proxy. More...

 #include <QNetworkProxy>

Note: All the functions in this class are reentrant.

This class was introduced in Qt 4.1.

Public Types

  • enum ProxyType { NoProxy, DefaultProxy, Socks5Proxy, HttpProxy, HttpCachingProxy, FtpCachingProxy }

Public Functions

Static Public Members


Detailed Description

The QNetworkProxy class provides a network layer proxy.

QNetworkProxy provides the method for configuring network layer proxy support to the Qt network classes. The currently supported classes are QAbstractSocket, QTcpSocket, QUdpSocket, QTcpServer, QHttp and QFtp. The proxy support is designed to be as transparent as possible. This means that existing network-enabled applications that you have written should automatically support network proxy using the following code.

 QNetworkProxy proxy;
 proxy.setType(QNetworkProxy::Socks5Proxy);
 proxy.setHostName("proxy.example.com");
 proxy.setPort(1080);
 proxy.setUser("username");
 proxy.setPassword("password");
 QNetworkProxy::setApplicationProxy(proxy);

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:

 serverSocket->setProxy(QNetworkProxy::NoProxy);

Network proxy is not used if the address used in connectToHost(), bind() or listen() is equivalent to QHostAddress::LocalHost or QHostAddress::LocalHostIPv6.

Each type of proxy support has certain restrictions associated with it. You should read the ProxyType documentation carefully before selecting a proxy type to use.

Note: Changes made to currently connected sockets do not take effect. If you need to change a connected socket, you should reconnect it.

SOCKS5

The SOCKS5 support in Qt 4 is based on RFC 1928 and RFC 1929. The supported authentication methods are no authentication and username/password authentication. Both IPv4 and IPv6 are supported, but domain name resolution via the SOCKS server is not supported; i.e. all domain names are resolved locally. There are several things to remember when using SOCKS5 with QUdpSocket and QTcpServer:

With QUdpSocket, a call to bind() may fail with a timeout error. If a port number other than 0 is passed to bind(), it is not guaranteed that it is the specified port that will be used. Use localPort() and localAddress() to get the actual address and port number in use. Because proxied UDP goes through two UDP connections, it is more likely that packets will be dropped.

With QTcpServer a call to listen() may fail with a timeout error. If a port number other than 0 is passed to listen(), then it is not guaranteed that it is the specified port that will be used. Use serverPort() and serverAddress() to get the actual address and port used to listen for connections. SOCKS5 only supports one accepted connection per call to listen(), and each call is likely to result in a different serverPort() being used.

See also QAbstractSocket and QTcpServer.


Member Type Documentation

enum QNetworkProxy::ProxyType

This enum describes the types of network proxying provided in Qt.

There are two types of proxies that Qt understands: transparent proxies and caching proxies. The first group consists of proxies that can handle any arbitrary data transfer, while the second can only handle specific requests. The caching proxies only make sense for the specific classes where they can be used.

ConstantValueDescription
QNetworkProxy::NoProxy2No proxying is used
QNetworkProxy::DefaultProxy0Proxy is determined based on the application proxy set using setApplicationProxy()
QNetworkProxy::Socks5Proxy1Socks5 proxying is used
QNetworkProxy::HttpProxy3HTTP transparent proxying is used
QNetworkProxy::HttpCachingProxy4Proxying for HTTP requests only
QNetworkProxy::FtpCachingProxy5Proxying for FTP requests only

The table below lists different proxy types and their capabilities. Since each proxy type has different capabilities, it is important to understand them before choosing a proxy type.

Proxy typeCapabilities
SOCKS 5Supports TCP, UDP, binding to a port (incoming connections) and authentication.
Transparent HTTPImplemented using the "CONNECT" command, supports only outgoing TCP connections; supports authentication.
Caching HTTPImplemented using normal HTTP commands, it is useful only in the context of HTTP requests (see QHttp, QNetworkAccessManager). The application's default proxy should not be set to the type HttpCachingProxy, since normal, outgoing TCP connections will fail, including those necessary to send the HTTP request in the first place.
Caching FTPImplemented using an FTP proxy, it is useful only in the context of FTP requests (see QFtp, QNetworkAccessManager). The application's default proxy should not be set to the type FtpCachingProxy since normal, outgoing TCP connections will fail, including those necessary to send the FTP request.

See also setType(), type(), isCachingProxy(), and isTransparentProxy().


Member Function Documentation

QNetworkProxy::QNetworkProxy ()

Constructs a QNetworkProxy with DefaultProxy type; the proxy type is determined by applicationProxy(), which defaults to NoProxy.

See also setType() and setApplicationProxy().

QNetworkProxy::QNetworkProxy ( ProxyType type, const QString & hostName = QString(), quint16 port = 0, const QString & user = QString(), const QString & password = QString() )

Constructs a QNetworkProxy with type, hostName, port, user and password.

QNetworkProxy::QNetworkProxy ( const QNetworkProxy & other )

Constructs a copy of other.

QNetworkProxy::~QNetworkProxy ()

Destroys the QNetworkProxy object.

QNetworkProxy QNetworkProxy::applicationProxy ()   [static]

Returns the application level network proxying.

If a QAbstractSocket or QTcpSocket has the QNetworkProxy::DefaultProxy type, then the QNetworkProxy returned by this function is used.

See also setApplicationProxy(), QAbstractSocket::proxy(), and QTcpServer::proxy().

QString QNetworkProxy::hostName () const

Returns the host name of the proxy host.

See also setHostName(), setPort(), and port().

bool QNetworkProxy::isCachingProxy () const

Returns true if this proxy type is a caching proxy. Caching proxies only make sense in specific contexts, since they cannot handle arbitrary data transfers.

This function was introduced in Qt 4.4.

See also type(), isTransparentProxy(), and QNetworkProxy::ProxyType.

bool QNetworkProxy::isTransparentProxy () const

Returns true if this proxy type is a transparent proxy. Transparent proxies can handle arbitrary data transfers and can be set on QTcpSocket or even as the application's default proxy.

This function was introduced in Qt 4.4.

See also type(), isCachingProxy(), and QNetworkProxy::ProxyType.

QString QNetworkProxy::password () const

Returns the password used for authentication.

See also user(), setPassword(), and setUser().

quint16 QNetworkProxy::port () const

Returns the port of the proxy host.

See also setHostName(), setPort(), and hostName().

void QNetworkProxy::setApplicationProxy ( const QNetworkProxy & networkProxy )   [static]

Sets the application level network proxying to be networkProxy.

If a QAbstractSocket or QTcpSocket has the QNetworkProxy::DefaultProxy type, then the QNetworkProxy set with this function is used.

See also applicationProxy(), QAbstractSocket::setProxy(), and QTcpServer::setProxy().

void QNetworkProxy::setHostName ( const QString & hostName )

Sets the host name of the proxy host to be hostName.

See also hostName(), setPort(), and port().

void QNetworkProxy::setPassword ( const QString & password )

Sets the password for proxy authentication to be password.

See also user(), setUser(), and password().

void QNetworkProxy::setPort ( quint16 port )

Sets the port of the proxy host to be port.

See also hostName(), setHostName(), and port().

void QNetworkProxy::setType ( QNetworkProxy::ProxyType type )

Sets the proxy type for this instance to be type.

See also type().

void QNetworkProxy::setUser ( const QString & user )

Sets the user name for proxy authentication to be user.

See also user(), setPassword(), and password().

QNetworkProxy::ProxyType QNetworkProxy::type () const

Returns the proxy type for this instance.

See also setType().

QString QNetworkProxy::user () const

Returns the user name used for authentication.

See also setUser(), setPassword(), and password().

bool QNetworkProxy::operator!= ( const QNetworkProxy & other ) const

Compares the value of this network proxy to other and returns true if they differ.

This function was introduced in Qt 4.4.

QNetworkProxy & QNetworkProxy::operator= ( const QNetworkProxy & other )

Assigns the value of the network proxy other to this network proxy.

This function was introduced in Qt 4.2.

bool QNetworkProxy::operator== ( const QNetworkProxy & other ) const

Compares the value of this network proxy to other and returns true if they are equal (same proxy type, server as well as username and password)

This function was introduced in Qt 4.4.

Publicité

Best Of

Actualités les plus lues

Semaine
Mois
Année
  1. « Quelque chose ne va vraiment pas avec les développeurs "modernes" », un développeur à "l'ancienne" critique la multiplication des bibliothèques 53
  2. Les développeurs ignorent-ils trop les failles découvertes dans leur code ? Prenez-vous en compte les remarques des autres ? 17
  3. Apercevoir la troisième dimension ou l'utilisation multithreadée d'OpenGL dans Qt, un article des Qt Quarterly traduit par Guillaume Belz 0
  4. BlackBerry 10 : premières images du prochain OS de RIM qui devrait intégrer des widgets et des tuiles inspirées de Windows Phone 0
  5. Quelles nouveautés de C++11 Visual C++ doit-il rapidement intégrer ? Donnez-nous votre avis 10
  6. Adieu qmake, bienvenue qbs : Qt Building Suite, un outil déclaratif et extensible pour la compilation de projets Qt 17
  7. La rubrique Qt a besoin de vous ! 1
Page suivante

Le Qt Labs au hasard

Logo

Le coût des commodités

Les Qt Labs sont les laboratoires des développeurs de Qt, où ils peuvent partager des impressions sur le framework, son utilisation, ce que pourrait être son futur. Lire l'article.

Communauté

Ressources

Liens utiles

Contact

  • Vous souhaitez rejoindre la rédaction ou proposer un tutoriel, une traduction, une question... ? Postez dans le forum Contribuez ou contactez-nous par MP ou par email (voir en bas de page).

Qt dans le magazine

Cette page est une traduction d'une page de la documentation de Qt, écrite par Nokia Corporation and/or its subsidiary(-ies). Les éventuels problèmes résultant d'une mauvaise traduction ne sont pas imputables à Nokia. Qt 4.4
Copyright © 2012 Developpez LLC. Tous droits réservés Developpez LLC. Aucune reproduction, même partielle, ne peut être faite de ce site et de l'ensemble de son contenu : textes, documents et images sans l'autorisation expresse de Developpez LLC. Sinon, vous encourez selon la loi jusqu'à 3 ans de prison et jusqu'à 300 000 E de dommages et intérêts. Cette page est déposée à la SACD.
Vous avez déniché une erreur ? Un bug ? Une redirection cassée ? Ou tout autre problème, quel qu'il soit ? Ou bien vous désirez participer à ce projet de traduction ? N'hésitez pas à nous contacter ou par MP !
 
 
 
 
Partenaires

Hébergement Web