QWebEngineDownloadRequest#
The QWebEngineDownloadRequest
class provides information about a download. More…
Synopsis#
Properties#
isFinished
- Whether this download is finished (completed, cancelled, or non-resumable interrupted state)isPaused
- Whether this download is paused
Functions#
def
downloadDirectory
()def
downloadFileName
()def
id
()def
interruptReason
()def
interruptReasonString
()def
isFinished
()def
isPaused
()def
isSavePageDownload
()def
mimeType
()def
page
()def
receivedBytes
()def
savePageFormat
()def
setDownloadDirectory
(directory)def
setDownloadFileName
(fileName)def
setSavePageFormat
(format)def
state
()def
suggestedFileName
()def
totalBytes
()def
url
()
Slots#
Signals#
def
downloadDirectoryChanged
()def
downloadFileNameChanged
()def
interruptReasonChanged
()def
isFinishedChanged
()def
isPausedChanged
()def
receivedBytesChanged
()def
savePageFormatChanged
()def
stateChanged
(state)def
totalBytesChanged
()
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
.
See also
- class PySide6.QtWebEngineCore.QWebEngineDownloadRequest#
Note
Properties can be used directly when from __feature__ import true_property
is used or via accessor functions otherwise.
- property PᅟySide6.QtWebEngineCore.QWebEngineDownloadRequest.downloadDirectory: str#
- Access functions:
setDownloadDirectory
(directory)Signal
downloadDirectoryChanged
()
- property PᅟySide6.QtWebEngineCore.QWebEngineDownloadRequest.downloadFileName: str#
- Access functions:
setDownloadFileName
(fileName)Signal
downloadFileNameChanged
()
- property PᅟySide6.QtWebEngineCore.QWebEngineDownloadRequest.id: int#
- Access functions:
id
()
- property PᅟySide6.QtWebEngineCore.QWebEngineDownloadRequest.interruptReason: DownloadInterruptReason#
- Access functions:
Signal
interruptReasonChanged
()
- property PᅟySide6.QtWebEngineCore.QWebEngineDownloadRequest.interruptReasonString: str#
- Access functions:
Signal
interruptReasonChanged
()
- property PᅟySide6.QtWebEngineCore.QWebEngineDownloadRequest.isFinished: bool#
This property holds Whether this download is finished (completed, cancelled, or non-resumable interrupted state)..
See also
- Access functions:
isFinished
()Signal
isFinishedChanged
()
- property PᅟySide6.QtWebEngineCore.QWebEngineDownloadRequest.isPaused: bool#
This property holds Whether this download is paused..
- Access functions:
isPaused
()Signal
isPausedChanged
()
- property PᅟySide6.QtWebEngineCore.QWebEngineDownloadRequest.isSavePageDownload: bool#
- Access functions:
- property PᅟySide6.QtWebEngineCore.QWebEngineDownloadRequest.mimeType: str#
- Access functions:
mimeType
()
- property PᅟySide6.QtWebEngineCore.QWebEngineDownloadRequest.receivedBytes: int#
- Access functions:
Signal
receivedBytesChanged
()
- property PᅟySide6.QtWebEngineCore.QWebEngineDownloadRequest.savePageFormat: SavePageFormat#
- Access functions:
setSavePageFormat
(format)Signal
savePageFormatChanged
()
- property PᅟySide6.QtWebEngineCore.QWebEngineDownloadRequest.state: DownloadState#
- Access functions:
state
()Signal
stateChanged
(state)
- property PᅟySide6.QtWebEngineCore.QWebEngineDownloadRequest.suggestedFileName: str#
- Access functions:
- property PᅟySide6.QtWebEngineCore.QWebEngineDownloadRequest.totalBytes: int#
- Access functions:
totalBytes
()Signal
totalBytesChanged
()
- property PᅟySide6.QtWebEngineCore.QWebEngineDownloadRequest.url: PySide6.QtCore.QUrl#
- Access functions:
url
()
- 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.
See also
- 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.
See also
- PySide6.QtWebEngineCore.QWebEngineDownloadRequest.downloadDirectory()#
- Return type:
str
Returns the download directory path.
See also
Getter of property downloadDirectory
.
- PySide6.QtWebEngineCore.QWebEngineDownloadRequest.downloadDirectoryChanged()#
Notification signal of property downloadDirectory
.
- PySide6.QtWebEngineCore.QWebEngineDownloadRequest.downloadFileName()#
- Return type:
str
Returns the file name to download the file to.
See also
Getter of property downloadFileName
.
- PySide6.QtWebEngineCore.QWebEngineDownloadRequest.downloadFileNameChanged()#
Notification signal of property downloadFileName
.
- PySide6.QtWebEngineCore.QWebEngineDownloadRequest.id()#
- Return type:
int
Returns the download item’s ID.
Getter of property id
.
- PySide6.QtWebEngineCore.QWebEngineDownloadRequest.interruptReason()#
- Return type:
Returns the reason why the download was interrupted.
See also
Getter of property interruptReason
.
- PySide6.QtWebEngineCore.QWebEngineDownloadRequest.interruptReasonChanged()#
Notification signal of property interruptReason
.
- PySide6.QtWebEngineCore.QWebEngineDownloadRequest.interruptReasonString()#
- Return type:
str
Returns a human-readable description of the reason for interrupting the download.
See also
Getter of property interruptReasonString
.
- PySide6.QtWebEngineCore.QWebEngineDownloadRequest.isFinished()#
- Return type:
bool
Getter of property isFinished
.
- PySide6.QtWebEngineCore.QWebEngineDownloadRequest.isFinishedChanged()#
Notification signal of property isFinished
.
- PySide6.QtWebEngineCore.QWebEngineDownloadRequest.isPaused()#
- Return type:
bool
Getter of property isPaused
.
- PySide6.QtWebEngineCore.QWebEngineDownloadRequest.isPausedChanged()#
This signal is emitted whenever isPaused
changes.
Notification signal of property isPaused
.
- PySide6.QtWebEngineCore.QWebEngineDownloadRequest.isSavePageDownload()#
- Return type:
bool
Returns true
if this is a download request for saving a web page.
See also
Getter of property isSavePageDownload
.
- PySide6.QtWebEngineCore.QWebEngineDownloadRequest.mimeType()#
- Return type:
str
Returns the MIME type of the download.
Getter of property mimeType
.
- PySide6.QtWebEngineCore.QWebEngineDownloadRequest.page()#
- Return type:
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
- PySide6.QtWebEngineCore.QWebEngineDownloadRequest.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
.
- PySide6.QtWebEngineCore.QWebEngineDownloadRequest.receivedBytesChanged()#
Notification signal of property receivedBytes
.
- 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.
See also
- PySide6.QtWebEngineCore.QWebEngineDownloadRequest.savePageFormat()#
- Return type:
Returns the format the web page will be saved in if this is a download request for a web page.
See also
Getter of property savePageFormat
.
- PySide6.QtWebEngineCore.QWebEngineDownloadRequest.savePageFormatChanged()#
Notification signal of property savePageFormat
.
- PySide6.QtWebEngineCore.QWebEngineDownloadRequest.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.
See also
Setter of property downloadDirectory
.
- PySide6.QtWebEngineCore.QWebEngineDownloadRequest.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.
See also
Setter of property downloadFileName
.
- PySide6.QtWebEngineCore.QWebEngineDownloadRequest.setSavePageFormat(format)#
- Parameters:
format –
SavePageFormat
Sets the format
the web page will be saved in if this is a download request for a web page.
See also
Setter of property savePageFormat
.
- PySide6.QtWebEngineCore.QWebEngineDownloadRequest.state()#
- Return type:
Returns the download item’s current state.
See also
DownloadState
Getter of property state
.
- PySide6.QtWebEngineCore.QWebEngineDownloadRequest.stateChanged(state)#
- Parameters:
state –
DownloadState
This signal is emitted whenever the download’s state
changes.
See also
state()
DownloadState
Notification signal of property state
.
- PySide6.QtWebEngineCore.QWebEngineDownloadRequest.suggestedFileName()#
- Return type:
str
Returns the suggested file name.
Getter of property suggestedFileName
.
- PySide6.QtWebEngineCore.QWebEngineDownloadRequest.totalBytes()#
- Return type:
int
Returns the the total amount of data to download in bytes.
-1
means the size is unknown.
Getter of property totalBytes
.
- PySide6.QtWebEngineCore.QWebEngineDownloadRequest.totalBytesChanged()#
Notification signal of property totalBytes
.
- PySide6.QtWebEngineCore.QWebEngineDownloadRequest.url()#
- Return type:
Returns the download’s origin URL.
Getter of property url
.