PySide6.QtWebEngineCore.QWebEngineDownloadRequest

class QWebEngineDownloadRequest

The QWebEngineDownloadRequest class provides information about a download. More

Inheritance diagram of PySide6.QtWebEngineCore.QWebEngineDownloadRequest

Synopsis

Properties

Methods

Slots

Signals

Note

This documentation may contain snippets that were automatically translated from C++ to Python. We always welcome contributions to the snippet translation. If you see an issue with the translation, you can also let us know by creating a ticket on https:/bugreports.qt.io/projects/PYSIDE

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. A signal handler must explicitly call accept() on the item for Qt WebEngine to actually start downloading and writing data to disk. If no signal handler calls accept() , then the download request will be automatically rejected and nothing will be written to disk.

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

All items are guaranteed to be valid during the emission of the downloadRequested signal. If accept() is not called by any signal handler, then the item will be deleted immediately after signal emission. This means that the application must not keep references to rejected download items. It also means the application should not use a queued connection to this signal.

If accept() is called by a signal handler, then the QWebEngineProfile will take 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 .

class DownloadState

This enum describes the state of the download:

Constant

Description

QWebEngineDownloadRequest.DownloadRequested

Download has been requested, but has not been accepted yet.

QWebEngineDownloadRequest.DownloadInProgress

Download is in progress.

QWebEngineDownloadRequest.DownloadCompleted

Download completed successfully.

QWebEngineDownloadRequest.DownloadCancelled

Download has been cancelled.

QWebEngineDownloadRequest.DownloadInterrupted

Download has been interrupted (by the server or because of lost connectivity).

class SavePageFormat

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

Constant

Description

QWebEngineDownloadRequest.UnknownSaveFormat

This is not a request for downloading a complete web page.

QWebEngineDownloadRequest.SingleHtmlSaveFormat

The page is saved as a single HTML page. Resources such as images are not saved.

QWebEngineDownloadRequest.CompleteHtmlSaveFormat

The page is saved as a complete HTML page, for example a directory containing the single HTML page and the resources.

QWebEngineDownloadRequest.MimeHtmlSaveFormat

The page is saved as a complete web page in the MIME HTML format.

class DownloadInterruptReason

Describes the reason why a download was interrupted:

Constant

Description

QWebEngineDownloadRequest.NoReason

Unknown reason or not interrupted.

QWebEngineDownloadRequest.FileFailed

General file operation failure.

QWebEngineDownloadRequest.FileAccessDenied

The file cannot be written locally, due to access restrictions.

QWebEngineDownloadRequest.FileNoSpace

Insufficient space on the target drive.

QWebEngineDownloadRequest.FileNameTooLong

The directory or file name is too long.

QWebEngineDownloadRequest.FileTooLarge

The file size exceeds the file system limitation.

QWebEngineDownloadRequest.FileVirusInfected

The file is infected with a virus.

QWebEngineDownloadRequest.FileTransientError

Temporary problem (for example the file is in use, out of memory, or too many files are opened at once).

QWebEngineDownloadRequest.FileBlocked

The file was blocked due to local policy.

QWebEngineDownloadRequest.FileSecurityCheckFailed

An attempt to check the safety of the download failed due to unexpected reasons.

QWebEngineDownloadRequest.FileTooShort

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

The partial file did not match the expected hash.

QWebEngineDownloadRequest.NetworkFailed

General network failure.

QWebEngineDownloadRequest.NetworkTimeout

The network operation has timed out.

QWebEngineDownloadRequest.NetworkDisconnected

The network connection has been terminated.

QWebEngineDownloadRequest.NetworkServerDown

The server has gone down.

QWebEngineDownloadRequest.NetworkInvalidRequest

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

General server failure.

QWebEngineDownloadRequest.ServerBadContent

The server does not have the requested data.

QWebEngineDownloadRequest.ServerUnauthorized

The server did not authorize access to the resource.

QWebEngineDownloadRequest.ServerCertProblem

A problem with the server certificate occurred.

QWebEngineDownloadRequest.ServerForbidden

Access forbidden by the server.

QWebEngineDownloadRequest.ServerUnreachable

Unexpected server response (might indicate that the responding server may not be the intended server).

QWebEngineDownloadRequest.UserCanceled

The user canceled the download.

Note

Properties can be used directly when from __feature__ import true_property is used or via accessor functions otherwise.

property downloadDirectoryᅟ: str
Access functions:
property downloadFileNameᅟ: str
Access functions:
property idᅟ: int
Access functions:
property interruptReasonᅟ: QWebEngineDownloadRequest.DownloadInterruptReason
Access functions:
property interruptReasonStringᅟ: str
Access functions:
property isFinishedᅟ: bool

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

See also

state()

Access functions:
property isPausedᅟ: bool

This property holds Whether this download is paused..

See also

pause() resume()

Access functions:
property isSavePageDownloadᅟ: bool
Access functions:
property mimeTypeᅟ: str
Access functions:
property receivedBytesᅟ: int
Access functions:
property savePageFormatᅟ: QWebEngineDownloadRequest.SavePageFormat
Access functions:
property stateᅟ: QWebEngineDownloadRequest.DownloadState
Access functions:
property suggestedFileNameᅟ: str
Access functions:
property totalBytesᅟ: int
Access functions:
property urlᅟ: QUrl
Access functions:
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.

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.

downloadDirectory()
Return type:

str

Returns the download directory path.

Getter of property downloadDirectoryᅟ .

downloadDirectoryChanged()

Notification signal of property downloadDirectoryᅟ .

downloadFileName()
Return type:

str

Returns the file name to download the file to.

Getter of property downloadFileNameᅟ .

downloadFileNameChanged()

Notification signal of property downloadFileNameᅟ .

id()
Return type:

int

Returns the download item’s ID.

Getter of property idᅟ .

interruptReason()
Return type:

DownloadInterruptReason

Returns the reason why the download was interrupted.

Getter of property interruptReasonᅟ .

interruptReasonChanged()

Notification signal of property interruptReasonᅟ .

interruptReasonString()
Return type:

str

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

Getter of property interruptReasonStringᅟ .

isFinished()
Return type:

bool

Getter of property isFinishedᅟ .

isFinishedChanged()

Notification signal of property isFinishedᅟ .

isPaused()
Return type:

bool

Getter of property isPausedᅟ .

isPausedChanged()

This signal is emitted whenever isPaused changes.

See also

pause() isPaused

Notification signal of property isPausedᅟ .

isSavePageDownload()
Return type:

bool

Returns true if this is a download request for saving a web page.

Getter of property isSavePageDownloadᅟ .

mimeType()
Return type:

str

Returns the MIME type of the download.

Getter of property mimeTypeᅟ .

page()
Return type:

QWebEnginePage

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

pause()

Pauses the download.

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

See also

resume() isPaused()

receivedBytes()
Return type:

int

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

-1 means the size is unknown.

Getter of property receivedBytesᅟ .

receivedBytesChanged()

Notification signal of property receivedBytesᅟ .

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.

savePageFormat()
Return type:

SavePageFormat

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

Getter of property savePageFormatᅟ .

savePageFormatChanged()

Notification signal of property savePageFormatᅟ .

setDownloadDirectory(directory)
Parameters:

directory – str

Sets directory as the directory path to download the file to.

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

Setter of property downloadDirectoryᅟ .

setDownloadFileName(fileName)
Parameters:

fileName – str

Sets fileName as the file name to download the file to.

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

Setter of property downloadFileNameᅟ .

setSavePageFormat(format)
Parameters:

formatSavePageFormat

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

Setter of property savePageFormatᅟ .

state()
Return type:

DownloadState

Returns the download item’s current state.

See also

DownloadState

Getter of property stateᅟ .

stateChanged(state)
Parameters:

stateDownloadState

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

Notification signal of property stateᅟ .

suggestedFileName()
Return type:

str

Returns the suggested file name.

Getter of property suggestedFileNameᅟ .

totalBytes()
Return type:

int

Returns the total amount of data to download in bytes.

-1 means the size is unknown.

Getter of property totalBytesᅟ .

totalBytesChanged()

Notification signal of property totalBytesᅟ .

url()
Return type:

QUrl

Returns the download’s origin URL.

Getter of property urlᅟ .