QWebEngineDownloadRequest#

The QWebEngineDownloadRequest class provides information about a download. More

Synopsis#

Functions#

Slots#

Signals#

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 PySide6.QtWebEngineCore.QWebEngineDownloadRequest#
PySide6.QtWebEngineCore.QWebEngineDownloadRequest.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).

PySide6.QtWebEngineCore.QWebEngineDownloadRequest.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.

PySide6.QtWebEngineCore.QWebEngineDownloadRequest.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.

PySide6.QtWebEngineCore.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.

PySide6.QtWebEngineCore.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.

PySide6.QtWebEngineCore.QWebEngineDownloadRequest.downloadDirectory()#
Return type

str

PySide6.QtWebEngineCore.QWebEngineDownloadRequest.downloadDirectoryChanged()#
PySide6.QtWebEngineCore.QWebEngineDownloadRequest.downloadFileName()#
Return type

str

PySide6.QtWebEngineCore.QWebEngineDownloadRequest.downloadFileNameChanged()#
PySide6.QtWebEngineCore.QWebEngineDownloadRequest.id()#
Return type

int

PySide6.QtWebEngineCore.QWebEngineDownloadRequest.interruptReason()#
Return type

DownloadInterruptReason

PySide6.QtWebEngineCore.QWebEngineDownloadRequest.interruptReasonChanged()#
PySide6.QtWebEngineCore.QWebEngineDownloadRequest.interruptReasonString()#
Return type

str

PySide6.QtWebEngineCore.QWebEngineDownloadRequest.isFinished()#
Return type

bool

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

See also

state()

PySide6.QtWebEngineCore.QWebEngineDownloadRequest.isFinishedChanged()#
PySide6.QtWebEngineCore.QWebEngineDownloadRequest.isPaused()#
Return type

bool

This property holds Whether this download is paused..

See also

pause() resume()

PySide6.QtWebEngineCore.QWebEngineDownloadRequest.isPausedChanged()#
PySide6.QtWebEngineCore.QWebEngineDownloadRequest.isSavePageDownload()#
Return type

bool

PySide6.QtWebEngineCore.QWebEngineDownloadRequest.mimeType()#
Return type

str

PySide6.QtWebEngineCore.QWebEngineDownloadRequest.page()#
Return type

PySide6.QtWebEngineCore.QWebEnginePage

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

PySide6.QtWebEngineCore.QWebEngineDownloadRequest.pause()#

Pauses the download.

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

See also

resume() isPaused()

PySide6.QtWebEngineCore.QWebEngineDownloadRequest.receivedBytes()#
Return type

int

PySide6.QtWebEngineCore.QWebEngineDownloadRequest.receivedBytesChanged()#
PySide6.QtWebEngineCore.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.

PySide6.QtWebEngineCore.QWebEngineDownloadRequest.savePageFormat()#
Return type

SavePageFormat

PySide6.QtWebEngineCore.QWebEngineDownloadRequest.savePageFormatChanged()#
PySide6.QtWebEngineCore.QWebEngineDownloadRequest.setDownloadDirectory(directory)#
Parameters

directory – str

PySide6.QtWebEngineCore.QWebEngineDownloadRequest.setDownloadFileName(fileName)#
Parameters

fileName – str

PySide6.QtWebEngineCore.QWebEngineDownloadRequest.setSavePageFormat(format)#
Parameters

formatSavePageFormat

PySide6.QtWebEngineCore.QWebEngineDownloadRequest.state()#
Return type

DownloadState

PySide6.QtWebEngineCore.QWebEngineDownloadRequest.stateChanged(state)#
Parameters

stateDownloadState

PySide6.QtWebEngineCore.QWebEngineDownloadRequest.suggestedFileName()#
Return type

str

PySide6.QtWebEngineCore.QWebEngineDownloadRequest.totalBytes()#
Return type

int

PySide6.QtWebEngineCore.QWebEngineDownloadRequest.totalBytesChanged()#
PySide6.QtWebEngineCore.QWebEngineDownloadRequest.url()#
Return type

PySide6.QtCore.QUrl