Qt之QNetworkAccessManager

QNetworkAccessManager类可以向服务器发送请求和接受应答。

QNetworkAccessManager类是网络访问API的主要部分,包含了对请求的配置与设置,还有监控网络操作过程的应答信号,以及其他相关信号。

简单事例如下:

  QNetworkAccessManager *manager = new QNetworkAccessManager(this);

  connect(manager, SIGNAL(finished(QNetworkReply*)), this, SLOT(replyFinished(QNetworkReply*)));

  manager->get(ANetworkRequest(QUrl("http://qt.nokia.com")));

当replyFinished(QNetworkReply*)被调用后,下载的数据和metadata会保存在QNetworkReply中。

当数据返回后,需要用户在合适的时间来删除QNetworkReply,不要直接在与finished相关联的槽中直接删除,可以使用deleteLater()删除。

QNetworkAccessManager会把收到的请求排队处理。


Public Types

enum NetworkAccessibility { UnknownAccessibility, NotAccessible, Accessible }
enum Operation { HeadOperation, GetOperation, PutOperation, PostOperation, DeleteOperation, CustomOperation }

Properties

  • networkAccessible : NetworkAccessibility
  • 1 property inherited from QObject

Public Functions

  QNetworkAccessManager ( QObject * parent = 0 )
  ~QNetworkAccessManager ()
QNetworkConfiguration activeConfiguration () const
QAbstractNetworkCache * cache () const
QNetworkConfiguration configuration () const
QNetworkCookieJar * cookieJar () const
QNetworkReply * deleteResource ( const QNetworkRequest & request )
QNetworkReply * get ( const QNetworkRequest & request )
QNetworkReply * head ( const QNetworkRequest & request )
NetworkAccessibility networkAccessible () const
QNetworkReply * post ( const QNetworkRequest & request, QIODevice * data )
QNetworkReply * post ( const QNetworkRequest & request, const QByteArray & data )
QNetworkReply * post ( const QNetworkRequest & request, QHttpMultiPart * multiPart )
QNetworkProxy proxy () const
QNetworkProxyFactory * proxyFactory () const
QNetworkReply * put ( const QNetworkRequest & request, QIODevice * data )
QNetworkReply * put ( const QNetworkRequest & request, QHttpMultiPart * multiPart )
QNetworkReply * put ( const QNetworkRequest & request, const QByteArray & data )
QNetworkReply * sendCustomRequest ( const QNetworkRequest & request, const QByteArray & verb, QIODevice * data = 0 )
void setCache ( QAbstractNetworkCache * cache )
void setConfiguration ( const QNetworkConfiguration & config )
void setCookieJar ( QNetworkCookieJar * cookieJar )
void setNetworkAccessible ( NetworkAccessibility accessible )
void setProxy ( const QNetworkProxy & proxy )
void setProxyFactory ( QNetworkProxyFactory * factory )
  • 29 public functions inherited from QObject

Signals

void authenticationRequired ( QNetworkReply * reply, QAuthenticator * authenticator )
void finished ( QNetworkReply * reply )
void networkAccessibleChanged ( QNetworkAccessManager::NetworkAccessibility accessible )
void proxyAuthenticationRequired ( const QNetworkProxy & proxy, QAuthenticator * authenticator )
void sslErrors ( QNetworkReply * reply, const QList & errors )
  • 1 signal inherited from QObject

Protected Functions

virtual QNetworkReply * createRequest ( Operation op, const QNetworkRequest & req, QIODevice * outgoingData = 0 )


你可能感兴趣的:(QtWebKit,网页解析)