PySide6.QtWebEngineCore.QWebEngineDownloadRequest¶
- class QWebEngineDownloadRequest¶
The
QWebEngineDownloadRequestclass provides information about a download. More…Inherited by:
QQuickWebEngineDownloadRequestSynopsis¶
Properties¶
isFinishedᅟ- Whether this download is finished (completed, cancelled, or non-resumable interrupted state)isPausedᅟ- Whether this download is paused
Methods¶
def
id()def
isFinished()def
isPaused()def
mimeType()def
page()def
receivedBytes()def
savePageFormat()def
state()def
totalBytes()def
url()
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¶
QWebEngineDownloadRequestmodels 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 thedownloadRequestedsignal together with a newly createdQWebEngineDownloadRequest. The application can then examine this item and decide whether to accept it or not. When a decision is made, the application must explicitly callaccept()orcancel()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()anddownloadFileName()), can only be changed before callingaccept().Object Life Cycle¶
In each and every case, the
QWebEngineProfiletakes the ownership of the item. However, it is safe for the application to delete the item at any time, except during the handling of thedownloadRequestedsignal. TheQWebEngineProfilebeing 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, useisSavePageDownload.Web page save requests are accepted automatically and started from
DownloadInProgressstate by convenience reasons. The first directly connecteddownloadRequestedsignal handler can prevent this by callingcancel(), otherwise the save operation will start writing data to the disk.See also
- class DownloadState¶
This enum describes the state of the download:
Constant
Description
QWebEngineDownloadRequest.DownloadState.DownloadRequested
Download has been requested, but has not been accepted yet.
QWebEngineDownloadRequest.DownloadState.DownloadInProgress
Download is in progress.
QWebEngineDownloadRequest.DownloadState.DownloadCompleted
Download completed successfully.
QWebEngineDownloadRequest.DownloadState.DownloadCancelled
Download has been cancelled.
QWebEngineDownloadRequest.DownloadState.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.SavePageFormat.UnknownSaveFormat
This is not a request for downloading a complete web page.
QWebEngineDownloadRequest.SavePageFormat.SingleHtmlSaveFormat
The page is saved as a single HTML page. Resources such as images are not saved.
QWebEngineDownloadRequest.SavePageFormat.CompleteHtmlSaveFormat
The page is saved as a complete HTML page, for example a directory containing the single HTML page and the resources.
QWebEngineDownloadRequest.SavePageFormat.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.DownloadInterruptReason.NoReason
Unknown reason or not interrupted.
QWebEngineDownloadRequest.DownloadInterruptReason.FileFailed
General file operation failure.
QWebEngineDownloadRequest.DownloadInterruptReason.FileAccessDenied
The file cannot be written locally, due to access restrictions.
QWebEngineDownloadRequest.DownloadInterruptReason.FileNoSpace
Insufficient space on the target drive.
QWebEngineDownloadRequest.DownloadInterruptReason.FileNameTooLong
The directory or file name is too long.
QWebEngineDownloadRequest.DownloadInterruptReason.FileTooLarge
The file size exceeds the file system limitation.
QWebEngineDownloadRequest.DownloadInterruptReason.FileVirusInfected
The file is infected with a virus.
QWebEngineDownloadRequest.DownloadInterruptReason.FileTransientError
Temporary problem (for example the file is in use, out of memory, or too many files are opened at once).
QWebEngineDownloadRequest.DownloadInterruptReason.FileBlocked
The file was blocked due to local policy.
QWebEngineDownloadRequest.DownloadInterruptReason.FileSecurityCheckFailed
An attempt to check the safety of the download failed due to unexpected reasons.
QWebEngineDownloadRequest.DownloadInterruptReason.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.DownloadInterruptReason.FileHashMismatch
The partial file did not match the expected hash.
QWebEngineDownloadRequest.DownloadInterruptReason.NetworkFailed
General network failure.
QWebEngineDownloadRequest.DownloadInterruptReason.NetworkTimeout
The network operation has timed out.
QWebEngineDownloadRequest.DownloadInterruptReason.NetworkDisconnected
The network connection has been terminated.
QWebEngineDownloadRequest.DownloadInterruptReason.NetworkServerDown
The server has gone down.
QWebEngineDownloadRequest.DownloadInterruptReason.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.DownloadInterruptReason.ServerFailed
General server failure.
QWebEngineDownloadRequest.DownloadInterruptReason.ServerBadContent
The server does not have the requested data.
QWebEngineDownloadRequest.DownloadInterruptReason.ServerUnauthorized
The server did not authorize access to the resource.
QWebEngineDownloadRequest.DownloadInterruptReason.ServerCertProblem
A problem with the server certificate occurred.
QWebEngineDownloadRequest.DownloadInterruptReason.ServerForbidden
Access forbidden by the server.
QWebEngineDownloadRequest.DownloadInterruptReason.ServerUnreachable
Unexpected server response (might indicate that the responding server may not be the intended server).
QWebEngineDownloadRequest.DownloadInterruptReason.UserCanceled
The user canceled the download.
Note
Properties can be used directly when
from __feature__ import true_propertyis 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
- Access functions:
Signal
isFinishedChanged()
- property isPausedᅟ: bool¶
This property holds Whether this download is paused..
- Access functions:
Signal
isPausedChanged()
- 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:
Signal
stateChanged()
- property suggestedFileNameᅟ: str¶
- Access functions:
- property totalBytesᅟ: int¶
- Access functions:
Signal
totalBytesChanged()
- Access functions:
- accept()¶
Accepts the current download request, which will start the download.
If the item is in the
DownloadRequestedstate, then it will transition into theDownloadInProgressstate and the downloading will begin. If the item is in any other state, then nothing will happen.See also
- cancel()¶
Cancels the current download.
If the item is in the
DownloadInProgressstate, then it will transition into theDownloadCancelledstate, the downloading will stop, and partially downloaded files will be deleted from disk.If the item is in the
DownloadCompletedstate, then nothing will happen. If the item is in any other state, then it will transition into theDownloadCancelledstate without further effect.See also
- downloadDirectory()¶
- Return type:
str
Returns the download directory path.
See also
Getter of property
downloadDirectoryᅟ.- downloadDirectoryChanged()¶
Notification signal of property
downloadDirectoryᅟ.- downloadFileName()¶
- Return type:
str
Returns the file name to download the file to.
See also
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:
Returns the reason why the download was interrupted.
See also
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.
See also
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
isPausedchanges.Notification signal of property
isPausedᅟ.- isSavePageDownload()¶
- Return type:
bool
Returns
trueif this is a download request for saving a web page.See also
Getter of property
isSavePageDownloadᅟ.- mimeType()¶
- Return type:
str
Returns the MIME type of the download.
Getter of property
mimeTypeᅟ.- page()¶
- Return type:
Returns the page the download was requested on. If the download was not triggered by content in a page,
nullptris returned.- pause()¶
Pauses the download.
Has no effect if the state is not
DownloadInProgress. Does not change the state.See also
- receivedBytes()¶
- Return type:
int
Returns the amount of data in bytes that has been downloaded so far.
-1means 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
DownloadInProgressorDownloadInterrupted. Does not change the state.See also
- 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ᅟ.- savePageFormatChanged()¶
Notification signal of property
savePageFormatᅟ.- setDownloadDirectory(directory)¶
- Parameters:
directory – str
Sets
directoryas 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ᅟ.- setDownloadFileName(fileName)¶
- Parameters:
fileName – str
Sets
fileNameas 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ᅟ.- setSavePageFormat(format)¶
- Parameters:
format –
SavePageFormat
Sets the
formatthe web page will be saved in if this is a download request for a web page.See also
Setter of property
savePageFormatᅟ.- state()¶
- Return type:
Returns the download item’s current state.
See also
Getter of property
stateᅟ.- stateChanged(state)¶
- Parameters:
state –
DownloadState
This signal is emitted whenever the download’s
statechanges.See also
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.
-1means the size is unknown.Getter of property
totalBytesᅟ.- totalBytesChanged()¶
Notification signal of property
totalBytesᅟ.Returns the download’s origin URL.
Getter of property
urlᅟ.