- Qt 6.11
- Qt WebEngine
- C++ Classes
- QtWebEngineCore
- QWebEngineDownloadRequest
- Qt 6.11.1 Reference Documentation

# QWebEngineDownloadRequest Class

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

Header: | `#include <QWebEngineDownloadRequest>`
CMake: | `find_package(Qt6 REQUIRED COMPONENTS WebEngineCore)` `target_link_libraries(mytarget PRIVATE Qt6::WebEngineCore)`
qmake: | `QT += webenginecore`
In QML: | WebEngineDownloadRequest
Inherits: | QObject

- List of all members, including inherited members

## Public Types

enum | DownloadInterruptReason { NoReason, FileFailed, FileAccessDenied, FileNoSpace, FileNameTooLong, …, UserCanceled }
enum | DownloadState { DownloadRequested, DownloadInProgress, DownloadCompleted, DownloadCancelled, DownloadInterrupted }
enum | SavePageFormat { UnknownSaveFormat, SingleHtmlSaveFormat, CompleteHtmlSaveFormat, MimeHtmlSaveFormat }

## Properties

downloadDirectory : QString downloadFileName : QString id : const quint32 interruptReason : DownloadInterruptReason interruptReasonString : QString isFinished : bool isPaused : bool isSavePageDownload : const bool | mimeType : QString receivedBytes : qint64 savePageFormat : SavePageFormat state : DownloadState suggestedFileName : const QString totalBytes : qint64 url : const QUrl

## Public Functions

QString | downloadDirectory() const
QString | downloadFileName() const
quint32 | id() const
QWebEngineDownloadRequest::DownloadInterruptReason | interruptReason() const
QString | interruptReasonString() const
bool | isFinished() const
bool | isPaused() const
bool | isSavePageDownload() const
QString | mimeType() const
QWebEnginePage * | page() const
qint64 | receivedBytes() const
QWebEngineDownloadRequest::SavePageFormat | savePageFormat() const
void | setDownloadDirectory(const QString &directory)
void | setDownloadFileName(const QString &fileName)
void | setSavePageFormat(QWebEngineDownloadRequest::SavePageFormat format)
QWebEngineDownloadRequest::DownloadState | state() const
QString | suggestedFileName() const
qint64 | totalBytes() const
QUrl | url() const

## Public Slots

void | accept()
void | cancel()
void | pause()
void | resume()

## Signals

void | downloadDirectoryChanged()
void | downloadFileNameChanged()
void | interruptReasonChanged()
void | isFinishedChanged()
void | isPausedChanged()
void | receivedBytesChanged()
void | savePageFormatChanged()
void | stateChanged(QWebEngineDownloadRequest::DownloadState state)
void | totalBytesChanged()

## Detailed Description

QWebEngineDownloadRequest models a download throughout its life cycle, starting with a pending download request and finishing with a completed download. It can be used, for example, to get information about new downloads, to monitor progress, and to pause, resume, and cancel downloads.

Downloads are usually triggered by user interaction on a web page. It is the QWebEngineProfile's responsibility to notify the application of new download requests, which it does by emitting the downloadRequested signal together with a newly created QWebEngineDownloadRequest. The application can then examine this item and decide whether to accept it or not. When a decision is made, the application must explicitly call accept() or cancel() on the item for Qt WebEngine to actually start downloading or rejecting the request.

Note: Some properties, such as setting the path and file name where the file will be saved (see downloadDirectory() and downloadFileName()), can only be changed before calling accept().

#### Object Life Cycle

In each and every case, the QWebEngineProfile takes the ownership of the item. However, it is safe for the application to delete the item at any time, except during the handling of the downloadRequested signal. The QWebEngineProfile being a long-lived object, it is in fact recommended that the application delete any items it is no longer interested in.

Note: Deleting an item will also automatically cancel a download since 5.12.2, but it is recommended to cancel manually before deleting for portability.

#### Web Page Downloads

In addition to normal file downloads, which consist simply of retrieving some raw bytes from the network and writing them to disk, Qt WebEngine also supports saving complete web pages, which involves parsing the page's HTML, downloading any dependent resources, and potentially packaging everything into a special file format (savePageFormat). To check if a download is for a file or a web page, use isSavePageDownload.

Web page save requests are accepted automatically and started from DownloadInProgress state by convenience reasons. The first directly connected downloadRequested signal handler can prevent this by calling cancel(), otherwise the save operation will start writing data to the disk.

See also QWebEngineProfile, QWebEngineProfile::downloadRequested, QWebEnginePage::download, and QWebEnginePage::save.

## Member Type Documentation

### enum QWebEngineDownloadRequest::DownloadInterruptReason

Describes the reason why a download was interrupted:

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

### enum QWebEngineDownloadRequest::DownloadState

This enum describes the state of the download:

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

### enum QWebEngineDownloadRequest::SavePageFormat

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

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

## Property Documentation

### downloadDirectory : QString

This property holds the download directory path.

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

Access functions:

QString | downloadDirectory() const
void | setDownloadDirectory(const QString &directory)

Notifier signal:

void | downloadDirectoryChanged()

### downloadFileName : QString

This property holds the file name to download the file to.

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

Access functions:

QString | downloadFileName() const
void | setDownloadFileName(const QString &fileName)

Notifier signal:

void | downloadFileNameChanged()

### `[read-only]` id : const quint32

This property holds the download item's ID.

Access functions:

quint32 | id() const

### `[read-only]` interruptReason : DownloadInterruptReason

This property holds the reason why the download was interrupted.

Access functions:

QWebEngineDownloadRequest::DownloadInterruptReason | interruptReason() const

Notifier signal:

void | interruptReasonChanged()

See also interruptReasonString.

### `[read-only]` interruptReasonString : QString

This property holds a human-readable description of the reason for interrupting the download.

Access functions:

QString | interruptReasonString() const

Notifier signal:

void | interruptReasonChanged()

See also interruptReason.

### `[read-only]` isFinished : bool

This property holds whether this download is finished (completed, cancelled, or non-resumable interrupted state).

Access functions:

bool | isFinished() const

Notifier signal:

void | isFinishedChanged()

See also state().

### `[read-only]` isPaused : bool

This property holds whether this download is paused.

Access functions:

bool | isPaused() const

Notifier signal:

void | isPausedChanged()

See also pause() and resume().

### `[read-only]` isSavePageDownload : const bool

This property holds whether this is a download request for saving a web page.

Access functions:

bool | isSavePageDownload() const

See also savePageFormat.

### `[read-only]` mimeType : QString

This property holds the MIME type of the download.

Access functions:

QString | mimeType() const

### `[read-only]` receivedBytes : qint64

This property holds the amount of data in bytes that has been downloaded so far.

`-1` means the size is unknown.

Access functions:

qint64 | receivedBytes() const

Notifier signal:

void | receivedBytesChanged()

### savePageFormat : SavePageFormat

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

Access functions:

QWebEngineDownloadRequest::SavePageFormat | savePageFormat() const
void | setSavePageFormat(QWebEngineDownloadRequest::SavePageFormat format)

Notifier signal:

void | savePageFormatChanged()

See also isSavePageDownload.

### `[read-only]` state : DownloadState

This property holds the download item's current state.

Access functions:

QWebEngineDownloadRequest::DownloadState | state() const

Notifier signal:

void | stateChanged(QWebEngineDownloadRequest::DownloadState state)

See also DownloadState.

### `[read-only]` suggestedFileName : const QString

This property holds the suggested file name.

Access functions:

QString | suggestedFileName() const

### `[read-only]` totalBytes : qint64

This property holds the total amount of data to download in bytes.

`-1` means the size is unknown.

Access functions:

qint64 | totalBytes() const

Notifier signal:

void | totalBytesChanged()

### `[read-only]` url : const QUrl

This property holds the download's origin URL.

Access functions:

QUrl | url() const

## Member Function Documentation

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

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

If the item is in the DownloadRequested state, then it will transition into the DownloadInProgress state and the downloading will begin. If the item is in any other state, then nothing will happen.

See also isFinished and stateChanged().

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

Cancels the current download.

If the item is in the DownloadInProgress state, then it will transition into the DownloadCancelled state, the downloading will stop, and partially downloaded files will be deleted from disk.

If the item is in the DownloadCompleted state, then nothing will happen. If the item is in any other state, then it will transition into the DownloadCancelled state without further effect.

See also isFinished and stateChanged().

### `[signal]` void QWebEngineDownloadRequest::isPausedChanged()

This signal is emitted whenever isPaused changes.

Note: Notifier signal for property isPaused.

See also pause() and isPaused.

### QWebEnginePage *QWebEngineDownloadRequest::page() const

Returns the page the download was requested on. If the download was not triggered by content in a page, `nullptr` is returned.

### `[slot]` void QWebEngineDownloadRequest::pause()

Pauses the download.

Has no effect if the state is not DownloadInProgress. Does not change the state.

See also resume() and isPaused().

### `[slot]` void QWebEngineDownloadRequest::resume()

Resumes the current download if it was paused or interrupted.

Has no effect if the state is not DownloadInProgress or DownloadInterrupted. Does not change the state.

See also pause(), isPaused(), and state().

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

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

Note: Notifier signal for property state.

See also state() and DownloadState.