Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## com.trolltech.qt.network
Class QNetworkAccessManager

    java.lang.Object
      com.trolltech.qt.QSignalEmitter
          com.trolltech.qt.QtJambiObject
              com.trolltech.qt.core.QObject
                  com.trolltech.qt.network.QNetworkAccessManager

All Implemented Interfaces:
  QtJambiInterface

    public class QNetworkAccessManager

extends QObject

The `QNetworkAccessManager` class allows the application to post network requests and receive replies The Network Access API is constructed around one `QNetworkAccessManager` object, which holds the common configuration and settings for the requests sent. It contains the proxy and cache configuration, as well as the signals related to such issues and reply signals.

Once a `QNetworkAccessManager` object has been created, the application can send requests over the network through that object. The methods in `QNetworkAccessManager` take a request and optionally some data to be uploaded and return a `QNetworkReply` object. The returned object is where most of the signals as well as the downloaded data are posted.

A simple download off the network could be accomplished with:
The following code example is written in c++.

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

            manager->get(QNetworkRequest("http://www.trolltech.com"));

When the `replyFinished` slot above is called, the parameter it takes is the `QNetworkReply` object containing the downloaded data as well as meta-data (headers, etc.).

Note: The slot is responsible for deleting the object at that point.

A more involved example, assuming the manager is already existent, can be:
The following code example is written in c++.

            QNetworkRequest request;
            request.setUrl("http://www.trolltech.com");
            request.setRawHeader("User-Agent", "MyOwnBrowser 1.0");

            QNetworkReply *reply = manager->get(request);
            connect(reply, SIGNAL(readyRead()), this, SLOT(slotReadyRead()));
            connect(reply, SIGNAL(error(QNetworkReply::NetworkError)),
                    this, SLOT(slotError(QNetworkReply::NetworkError)));
            connect(reply, SIGNAL(sslErrors(QList<QSslError>)),
                    this, SLOT(slotSslErrors(QList<QSslError)));

See also:
  `QNetworkRequest`, `QNetworkReply`, and `QNetworkProxy`.

Nested Class Summary
`static class` | `QNetworkAccessManager.Operation`

Nested classes/interfaces inherited from class com.trolltech.qt.QSignalEmitter
`QSignalEmitter.Signal0, QSignalEmitter.Signal1, QSignalEmitter.Signal2, QSignalEmitter.Signal3, QSignalEmitter.Signal4, QSignalEmitter.Signal5, QSignalEmitter.Signal6, QSignalEmitter.Signal7, QSignalEmitter.Signal8, QSignalEmitter.Signal9`

Field Summary
`QSignalEmitter.Signal2` | `authenticationRequired` This signal is emitted whenever a final server requests authentication before it delivers the requested contents.
`QSignalEmitter.Signal1` | `finished` This signal is emitted whenever a pending network reply is finished.
`QSignalEmitter.Signal2` | `proxyAuthenticationRequired` This signal is emitted whenever a proxy requests authentication and `QNetworkAccessManager` cannot find a valid, cached credential.

Constructor Summary
`QNetworkAccessManager()` Constructs a `QNetworkAccessManager` object that is the center of the Network Access API and sets `parent` as the parent object.
`QNetworkAccessManager(QObject parent)` Constructs a `QNetworkAccessManager` object that is the center of the Network Access API and sets `parent` as the parent object.

Method Summary
`QNetworkCookieJar` | `cookieJar()` Returns the `QNetworkCookieJar` that is used to store cookies obtained from the network as well as cookies that are about to be sent.
`protected QNetworkReply` | `createRequest(QNetworkAccessManager.Operation op, QNetworkRequest request)` Returns a new `QNetworkReply` object to handle the operation `op` and request `req`.
`protected QNetworkReply` | `createRequest(QNetworkAccessManager.Operation op, QNetworkRequest request, QIODevice outgoingData)` Returns a new `QNetworkReply` object to handle the operation `op` and request `req`.
`static QNetworkAccessManager` | `fromNativePointer(QNativePointer nativePointer)` This method returns the QNetworkAccessManager instance pointed to by `nativePointer`.
`QNetworkReply` | `get(QNetworkRequest request)` This function is used to post a request to obtain the contents of the target `request`.
`QNetworkReply` | `head(QNetworkRequest request)` This function is used to post a request to obtain the network headers for `request`.
`QNetworkReply` | `post(QNetworkRequest request, QByteArray data)` This function sends the contents of the `data` byte array to the destination specified by `request`.
`QNetworkReply` | `post(QNetworkRequest request, QIODevice data)` This function is used to send an HTTP POST request to the destination specified by `request`.
`QNetworkProxy` | `proxy()` Returns the `QNetworkProxy` that the requests sent using this `QNetworkAccessManager` object will use.
`QNetworkReply` | `put(QNetworkRequest request, QByteArray data)` This function sends the contents of the `data` byte array to the destination specified by `request`.
`QNetworkReply` | `put(QNetworkRequest request, QIODevice data)` This function is used to upload the contents of `data` to the destination `request`.
`void` | `setCookieJar(QNetworkCookieJar cookieJar)` Sets the cookie jar that is used by all request sent using this `QNetworkAccessManager` object to be `cookieJar`.
`void` | `setProxy(QNetworkProxy proxy)` Sets the proxy to be used in future requests to be `proxy`.

Methods inherited from class com.trolltech.qt.core.QObject
`childEvent, children, connectSlotsByName, customEvent, disposeLater, dumpObjectInfo, dumpObjectTree, dynamicPropertyNames, event, eventFilter, findChild, findChild, findChild, findChildren, findChildren, findChildren, findChildren, indexOfProperty, installEventFilter, isWidgetType, killTimer, moveToThread, objectName, parent, properties, property, removeEventFilter, setObjectName, setParent, setProperty, startTimer, timerEvent, toString, userProperty`

Methods inherited from class com.trolltech.qt.QtJambiObject
`dispose, disposed, equals, finalize, reassignNativeResources, tr, tr, tr`

Methods inherited from class com.trolltech.qt.QSignalEmitter
`blockSignals, disconnect, disconnect, signalsBlocked, signalSender, thread`

Methods inherited from class java.lang.Object
`clone, getClass, hashCode, notify, notifyAll, wait, wait, wait`

Methods inherited from interface com.trolltech.qt.QtJambiInterface
`disableGarbageCollection, nativeId, nativePointer, reenableGarbageCollection, setJavaOwnership`

Field Detail

### finished

    public final QSignalEmitter.Signal1 finished

  This signal is emitted whenever a pending network reply is finished. The `reply` parameter will contain a pointer to the reply that has just finished. This signal is emitted in tandem with the `QNetworkReply::finished()` signal.

  See `QNetworkReply::finished()` for information on the status that the object will be in.

See also:
  `QNetworkReply::finished()` , and `QNetworkReply::error()`.

### proxyAuthenticationRequired

    public QSignalEmitter.Signal2 proxyAuthenticationRequired

  This signal is emitted whenever a proxy requests authentication and `QNetworkAccessManager` cannot find a valid, cached credential. The slot connected to this signal should fill in the credentials for the proxy `proxy` in the `authenticator` object.

  `QNetworkAccessManager` will cache the credentials internally. The next time the proxy requests authentication, `QNetworkAccessManager` will automatically send the same credential without emitting the `proxyAuthenticationRequired` signal again.

  If the proxy rejects the credentials, `QNetworkAccessManager` will emit the signal again.

See also:
  `proxy()`, `setProxy()`, and `authenticationRequired()` .

### authenticationRequired

    public QSignalEmitter.Signal2 authenticationRequired

  This signal is emitted whenever a final server requests authentication before it delivers the requested contents. The slot connected to this signal should fill the credentials for the contents (which can be determined by inspecting the `reply` object) in the `authenticator` object.

  `QNetworkAccessManager` will cache the credentials internally and will send the same values if the server requires authentication again, without emitting the `authenticationRequired()` signal. If it rejects the credentials, this signal will be emitted again.

See also:
  `proxyAuthenticationRequired()` .

Constructor Detail

### QNetworkAccessManager

    public QNetworkAccessManager()

  Constructs a `QNetworkAccessManager` object that is the center of the Network Access API and sets `parent` as the parent object.

### QNetworkAccessManager

    public QNetworkAccessManager(QObject parent)

  Constructs a `QNetworkAccessManager` object that is the center of the Network Access API and sets `parent` as the parent object.

Method Detail

### cookieJar

    public final QNetworkCookieJar cookieJar()

  Returns the `QNetworkCookieJar` that is used to store cookies obtained from the network as well as cookies that are about to be sent.

See also:
  `setCookieJar()`.

### get

    public final QNetworkReply get(QNetworkRequest request)

  This function is used to post a request to obtain the contents of the target `request`. It will cause the contents to be downloaded, along with the headers associated with it. It returns a new `QNetworkReply` object opened for reading which emits its `QIODevice::readyRead()` signal whenever new data arrives.

See also:
  `post()`, and `put()`.

### head

    public final QNetworkReply head(QNetworkRequest request)

  This function is used to post a request to obtain the network headers for `request`. It takes its name after the HTTP request associated (HEAD). It returns a new `QNetworkReply` object which will contain such headers.

### post

    public final QNetworkReply post(QNetworkRequest request,
                                    QIODevice data)

  This function is used to send an HTTP POST request to the destination specified by `request`. The contents of the `data` device will be uploaded to the server.

  `data` must be opened for reading when this function is called and must remain valid until the `finished()` signal is emitted for this reply.

  The returned `QNetworkReply` object will be open for reading and will contain the reply sent by the server to the POST request.

  Note: sending a POST request on protocols other than HTTP and HTTPS is undefined and will probably fail.

See also:
  `get()`, and `put()`.

### post

    public final QNetworkReply post(QNetworkRequest request,
                                    QByteArray data)

  This function sends the contents of the `data` byte array to the destination specified by `request`.

### proxy

    public final QNetworkProxy proxy()

  Returns the `QNetworkProxy` that the requests sent using this `QNetworkAccessManager` object will use. By default, `QNetworkAccessManager` uses the application global proxy settings.

See also:
  `setProxy()`, and `proxyAuthenticationRequired()` .

### put

    public final QNetworkReply put(QNetworkRequest request,
                                   QIODevice data)

  This function is used to upload the contents of `data` to the destination `request`.

  `data` must be opened for reading when this function is called and must remain valid until the `finished()` signal is emitted for this reply.

  The returned `QNetworkReply` object will be open for reply, but whether anything will be available for reading is protocol dependent. For HTTP, the server may send a small HTML page indicating the upload was successful (or not). Other protocols will probably have content in their replies.

  For HTTP, this request will send a PUT request, which most servers do not allow. Form upload mechanisms, including that of uploading files through HTML forms, use the POST mechanism.

See also:
  `get()`, and `post()`.

### put

    public final QNetworkReply put(QNetworkRequest request,
                                   QByteArray data)

  This function sends the contents of the `data` byte array to the destination specified by `request`.

### setCookieJar

    public final void setCookieJar(QNetworkCookieJar cookieJar)

  Sets the cookie jar that is used by all request sent using this `QNetworkAccessManager` object to be `cookieJar`. Use this function to set the cookie jar object to a class that implements further features, like saving the cookies to permanent storage.

  Note that `QNetworkAccessManager` takes ownership of the object `cookieJar`.

  `QNetworkAccessManager` by default does not implement any cookie policy of its own: it accepts all cookies sent by the server, as long as they are well formed and meet the minimum security requirements (cookie domain matches the request's and cookie path matches the request's). In order to implement your own security policy, override the `QNetworkCookieJar::cookiesForUrl()` and `QNetworkCookieJar::setCookiesFromUrl()` virtual functions. Those functions are called by `QNetworkAccessManager` when it detects a new cookie.

See also:
  `cookieJar()`, `QNetworkCookieJar::cookiesForUrl()`, and `QNetworkCookieJar::setCookiesFromUrl()`.

### setProxy

    public final void setProxy(QNetworkProxy proxy)

  Sets the proxy to be used in future requests to be `proxy`. This does not affect requests that have already been sent. The `proxyAuthenticationRequired()` signal will be emitted if the proxy requests authentication.

See also:
  `proxy()`, and `proxyAuthenticationRequired()` .

### createRequest

    protected final QNetworkReply createRequest(QNetworkAccessManager.Operation op,
                                                QNetworkRequest request)

  Returns a new `QNetworkReply` object to handle the operation `op` and request `req`. The device `outgoingData` is always 0 for Get and Head requests, but is the value passed to `post()` and `put()` in those operations (the `QByteArray` variants will pass a `QBuffer` object).

  The default implementation calls `QNetworkCookieJar::cookiesForUrl()` on the cookie jar set with `setCookieJar()` to obtain the cookies to be sent to the remote server.

  The returned object must be in an open state.

### createRequest

    protected QNetworkReply createRequest(QNetworkAccessManager.Operation op,
                                          QNetworkRequest request,
                                          QIODevice outgoingData)

  Returns a new `QNetworkReply` object to handle the operation `op` and request `req`. The device `outgoingData` is always 0 for Get and Head requests, but is the value passed to `post()` and `put()` in those operations (the `QByteArray` variants will pass a `QBuffer` object).

  The default implementation calls `QNetworkCookieJar::cookiesForUrl()` on the cookie jar set with `setCookieJar()` to obtain the cookies to be sent to the remote server.

  The returned object must be in an open state.

### fromNativePointer

    public static QNetworkAccessManager fromNativePointer(QNativePointer nativePointer)

  This method returns the QNetworkAccessManager instance pointed to by `nativePointer`.

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD