Qt 5.9 | Qt WebEngine | C++ Classes | QWebEngineDownloadItem

Qt 5.9.9 Reference Documentation

# QWebEngineDownloadItem Class

The QWebEngineDownloadItem class provides information about a download. More...

Header: | #include <QWebEngineDownloadItem>
qmake: | QT += webenginewidgets
Since: | Qt 5.5

- List of all members, including inherited members

## Public Types

enum | DownloadInterruptReason { NoReason, FileFailed, FileAccessDenied, FileNoSpace, ..., UserCanceled }
enum | DownloadState { DownloadRequested, DownloadInProgress, DownloadCompleted, DownloadCancelled, DownloadInterrupted }
enum | DownloadType { Attachment, DownloadAttribute, UserRequested, SavePage }
enum | SavePageFormat { UnknownSaveFormat, SingleHtmlSaveFormat, CompleteHtmlSaveFormat, MimeHtmlSaveFormat }

## Public Functions

quint32 | id() const
DownloadInterruptReason | interruptReason() const
QString | interruptReasonString() const
bool | isFinished() const
QString | mimeType() const
QString | path() const
qint64 | receivedBytes() const
SavePageFormat | savePageFormat() const
void | setPath(QString path)
void | setSavePageFormat(SavePageFormat format)
DownloadState | state() const
qint64 | totalBytes() const
DownloadType | type() const
QUrl | url() const

## Public Slots

void | accept()
void | cancel()

## Signals

void | downloadProgress(qint64 bytesReceived, qint64 bytesTotal)
void | finished()
void | stateChanged(QWebEngineDownloadItem::DownloadState state)

## Detailed Description

The QWebEngineDownloadItem class provides information about a download.

QWebEngineDownloadItem stores the state of a download to be used to manage requested downloads.

## Member Type Documentation

### enum QWebEngineDownloadItem::DownloadInterruptReason

Describes the reason why a download was interrupted:

Constant | Value | Description
--- | --- | ---
`QWebEngineDownloadItem::NoReason` | `0` | Unknown reason or not interrupted.
`QWebEngineDownloadItem::FileFailed` | `1` | General file operation failure.
`QWebEngineDownloadItem::FileAccessDenied` | `2` | The file cannot be written locally, due to access restrictions.
`QWebEngineDownloadItem::FileNoSpace` | `3` | Insufficient space on the target drive.
`QWebEngineDownloadItem::FileNameTooLong` | `5` | The directory or file name is too long.
`QWebEngineDownloadItem::FileTooLarge` | `6` | The file size exceeds the file system limitation.
`QWebEngineDownloadItem::FileVirusInfected` | `7` | The file is infected with a virus.
`QWebEngineDownloadItem::FileTransientError` | `10` | Temporary problem (for example the file is in use, out of memory, or too many files are opened at once).
`QWebEngineDownloadItem::FileBlocked` | `11` | The file was blocked due to local policy.
`QWebEngineDownloadItem::FileSecurityCheckFailed` | `12` | An attempt to check the safety of the download failed due to unexpected reasons.
`QWebEngineDownloadItem::FileTooShort` | `13` | An attempt was made to seek past the end of a file when opening a file (as part of resuming a previously interrupted download).
`QWebEngineDownloadItem::FileHashMismatch` | `14` | The partial file did not match the expected hash.
`QWebEngineDownloadItem::NetworkFailed` | `20` | General network failure.
`QWebEngineDownloadItem::NetworkTimeout` | `21` | The network operation has timed out.
`QWebEngineDownloadItem::NetworkDisconnected` | `22` | The network connection has been terminated.
`QWebEngineDownloadItem::NetworkServerDown` | `23` | The server has gone down.
`QWebEngineDownloadItem::NetworkInvalidRequest` | `24` | The network request was invalid (for example, the original or redirected URL is invalid, has an unsupported scheme, or is disallowed by policy).
`QWebEngineDownloadItem::ServerFailed` | `30` | General server failure.
`QWebEngineDownloadItem::ServerBadContent` | `33` | The server does not have the requested data.
`QWebEngineDownloadItem::ServerUnauthorized` | `34` | The server did not authorize access to the resource.
`QWebEngineDownloadItem::ServerCertProblem` | `35` | A problem with the server certificate occurred.
`QWebEngineDownloadItem::ServerForbidden` | `36` | Access forbidden by the server.
`QWebEngineDownloadItem::ServerUnreachable` | `37` | Unexpected server response (might indicate that the responding server may not be the intended server).
`QWebEngineDownloadItem::UserCanceled` | `40` | The user canceled the download.

This enum was introduced or modified in Qt 5.9.

### enum QWebEngineDownloadItem::DownloadState

This enum describes the state of the download:

Constant | Value | Description
--- | --- | ---
`QWebEngineDownloadItem::DownloadRequested` | `0` | Download has been requested, but has not been accepted yet.
`QWebEngineDownloadItem::DownloadInProgress` | `1` | Download is in progress.
`QWebEngineDownloadItem::DownloadCompleted` | `2` | Download completed successfully.
`QWebEngineDownloadItem::DownloadCancelled` | `3` | Download has been cancelled.
`QWebEngineDownloadItem::DownloadInterrupted` | `4` | Download has been interrupted (by the server or because of lost connectivity).

### enum QWebEngineDownloadItem::DownloadType

Describes the requested download's type.

Constant | Value | Description
--- | --- | ---
`QWebEngineDownloadItem::Attachment` | `0` | The web server's response includes a `Content-Disposition` header with the `attachment` directive. If `Content-Disposition` is present in the reply, the web server is indicating that the client should prompt the user to save the content regardless of the content type. See RFC 2616 section 19.5.1 for details.
`QWebEngineDownloadItem::DownloadAttribute` | `1` | The user clicked a link with the `download` attribute. See HTML download attribute for details.
`QWebEngineDownloadItem::UserRequested` | `2` | The user initiated the download, for example by selecting a web action.
`QWebEngineDownloadItem::SavePage` | `3` | Saving of the current page was requested (for example by the QWebEnginePage::SavePage web action).

This enum was introduced or modified in Qt 5.8.

### enum QWebEngineDownloadItem::SavePageFormat

This enum describes the format that is used to save a web page.

Constant | Value | Description
--- | --- | ---
`QWebEngineDownloadItem::UnknownSaveFormat` | `-1` | This is not a request for downloading a complete web page.
`QWebEngineDownloadItem::SingleHtmlSaveFormat` | `0` | The page is saved as a single HTML page. Resources such as images are not saved.
`QWebEngineDownloadItem::CompleteHtmlSaveFormat` | `1` | The page is saved as a complete HTML page, for example a directory containing the single HTML page and the resources.
`QWebEngineDownloadItem::MimeHtmlSaveFormat` | `2` | The page is saved as a complete web page in the MIME HTML format.

This enum was introduced or modified in Qt 5.7.

## Member Function Documentation

### `[slot]` void QWebEngineDownloadItem::accept()

Accepts the current download request, which will start the download.

See also finished() and stateChanged().

### `[slot]` void QWebEngineDownloadItem::cancel()

Cancels the current download.

See also finished() and stateChanged().

### `[signal]` void QWebEngineDownloadItem::downloadProgress(qint64 bytesReceived, qint64 bytesTotal)

This signal is emitted to indicate the progress of the download request.

The bytesReceived parameter indicates the number of bytes received, while bytesTotal indicates the total number of bytes expected to be downloaded. If the size of the file to be downloaded is not known, `bytesTotal` will be 0.

See also totalBytes() and receivedBytes().

### `[signal]` void QWebEngineDownloadItem::finished()

This signal is emitted whenever the download finishes.

See also state() and isFinished().

### quint32 QWebEngineDownloadItem::id() const

Returns the download item's ID.

### DownloadInterruptReason QWebEngineDownloadItem::interruptReason() const

Returns the reason why the download was interrupted.

This function was introduced in Qt 5.9.

See also interruptReasonString().

### QString QWebEngineDownloadItem::interruptReasonString() const

Returns a human-readable description of the reason for interrupting the download.

This function was introduced in Qt 5.9.

See also interruptReason().

### bool QWebEngineDownloadItem::isFinished() const

Returns whether this download is finished (not in progress).

See also finished() and state().

### QString QWebEngineDownloadItem::mimeType() const

Returns the MIME type of the download.

This function was introduced in Qt 5.6.

### QString QWebEngineDownloadItem::path() const

Returns the full target path where data is being downloaded to.

The path includes the file name. The default suggested path is the standard download location and file name is deduced not to overwrite already existing files.

See also setPath().

### qint64 QWebEngineDownloadItem::receivedBytes() const

Returns the amount of data in bytes that has been downloaded so far.

`-1` means the size is unknown.

### SavePageFormat QWebEngineDownloadItem::savePageFormat() const

Returns the format the web page will be saved in if this is a download request for a web page.

This function was introduced in Qt 5.7.

See also setSavePageFormat().

### void QWebEngineDownloadItem::setPath(QString path)

Sets the full target path to download the file to.

The path should also include the file name. The download path can only be set in response to the QWebEngineProfile::downloadRequested() signal before the download is accepted. Past that point, this function has no effect on the download item's state.

See also path().

### void QWebEngineDownloadItem::setSavePageFormat(SavePageFormat format)

Sets the format the web page will be saved in if this is a download request for a web page.

This function was introduced in Qt 5.7.

See also savePageFormat().

### DownloadState QWebEngineDownloadItem::state() const

Returns the download item's current state.

See also DownloadState.

### `[signal]` void QWebEngineDownloadItem::stateChanged(QWebEngineDownloadItem::DownloadState state)

This signal is emitted whenever the download's state changes.

See also state() and DownloadState.

### qint64 QWebEngineDownloadItem::totalBytes() const

Returns the the total amount of data to download in bytes.

`-1` means the size is unknown.

### DownloadType QWebEngineDownloadItem::type() const

Returns the requested download's type.

This function was introduced in Qt 5.8.

### QUrl QWebEngineDownloadItem::url() const

Returns the download's origin URL.