WebEngineDownloadItem QML Type▲
-
Import Statement: import QtWebEngine 1.8
-
Since: QtWebEngine 1.1
Detailed Description▲
WebEngineDownloadItem 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 WebEngineProfile's responsibility to notify the application of new download requests, which it does by emitting the downloadRequested signal together with a newly created WebEngineDownloadItem. 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.
Some properties, like the path under which the file will be saved, 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.
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▲
Property Documentation▲
id : int▲
Holds the download item's ID.
[read-only, since QtWebEngine 1.5] interruptReason : enumeration▲
Returns the reason why the download was interrupted:
Constant |
Description |
---|---|
WebEngineDownloadItem.NoReason |
Unknown reason or not interrupted. |
WebEngineDownloadItem.FileFailed |
General file operation failure. |
WebEngineDownloadItem.FileAccessDenied |
The file cannot be written locally, due to access restrictions. |
WebEngineDownloadItem.FileNoSpace |
Insufficient space on the target drive. |
WebEngineDownloadItem.FileNameTooLong |
The directory or file name is too long. |
WebEngineDownloadItem.FileTooLarge |
The file size exceeds the file system limitation. |
WebEngineDownloadItem.FileVirusInfected |
The file is infected with a virus. |
WebEngineDownloadItem.FileTransientError |
Temporary problem (for example the file is in use, out of memory, or too many files are opened at once). |
WebEngineDownloadItem.FileBlocked |
The file was blocked due to local policy. |
WebEngineDownloadItem.FileSecurityCheckFailed |
An attempt to check the safety of the download failed due to unexpected reasons. |
WebEngineDownloadItem.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). |
WebEngineDownloadItem.FileHashMismatch |
The partial file did not match the expected hash. |
WebEngineDownloadItem.NetworkFailed |
General network failure. |
WebEngineDownloadItem.NetworkTimeout |
The network operation has timed out. |
WebEngineDownloadItem.NetworkDisconnected |
The network connection has been terminated. |
WebEngineDownloadItem.NetworkServerDown |
The server has gone down. |
WebEngineDownloadItem.NetworkInvalidRequest |
The network request was invalid (for example, the original or redirected URL is invalid, has an unsupported scheme, or is disallowed by policy). |
WebEngineDownloadItem.ServerFailed |
General server failure. |
WebEngineDownloadItem.ServerBadContent |
The server does not have the requested data. |
WebEngineDownloadItem.ServerUnauthorized |
The server did not authorize access to the resource. |
WebEngineDownloadItem.ServerCertProblem |
A problem with the server certificate occurred. |
WebEngineDownloadItem.ServerForbidden |
Access forbidden by the server. |
WebEngineDownloadItem.ServerUnreachable |
Unexpected server response (might indicate that the responding server may not be the intended server). |
WebEngineDownloadItem.UserCanceled |
The user canceled the download. |
This property was introduced in QtWebEngine 1.5.
See Also▲
See also interruptReasonString
[since QtWebEngine 1.5] interruptReasonString : string▲
Returns a human-readable description of the reason for interrupting the download.
This property was introduced in QtWebEngine 1.5.
See Also▲
See also interruptReason
[read-only, since QtWebEngine 1.6] isFinished : bool▲
Whether this download is finished (completed, cancelled, or non-resumable interrupted state).
This property was introduced in QtWebEngine 1.6.
[read-only, since QtWebEngine 1.6] isPaused : bool▲
[read-only, since QtWebEngine 1.7] isSavePageDownload : bool▲
Whether this is a download request for saving a web page or a file.
This property was introduced in QtWebEngine 1.7.
See Also▲
See also savePageFormat
[since QtWebEngine 1.2] mimeType : string▲
Holds the MIME type of the download.
This property was introduced in QtWebEngine 1.2.
path : string▲
Holds the full target path where data is being downloaded to.
The path includes the file name. The default suggested path is the standard download location and file name is deduced not to overwrite already existing files.
The download path can only be set in the downloadRequested handler before the download is accepted.
See Also▲
See also WebEngineProfile::downloadRequested(), accept()
receivedBytes : int▲
Holds the amount of data in bytes that has been downloaded so far.
[since QtWebEngine 1.3] savePageFormat : enumeration▲
Describes the format that is used to save a web page.
Constant |
Description |
---|---|
WebEngineDownloadItem.UnknownSaveFormat |
This is not a request for downloading a complete web page. |
WebEngineDownloadItem.SingleHtmlSaveFormat |
The page is saved as a single HTML page. Resources such as images are not saved. |
WebEngineDownloadItem.CompleteHtmlSaveFormat |
The page is saved as a complete HTML page, for example a directory containing the single HTML page and the resources. |
WebEngineDownloadItem.MimeHtmlSaveFormat |
The page is saved as a complete web page in the MIME HTML format. |
This property was introduced in QtWebEngine 1.3.
state : enumeration▲
Describes the state of the download:
Constant |
Description |
---|---|
WebEngineDownloadItem.DownloadRequested |
Download has been requested, but it has not been accepted yet. |
WebEngineDownloadItem.DownloadInProgress |
Download is in progress. |
WebEngineDownloadItem.DownloadCompleted |
Download completed successfully. |
WebEngineDownloadItem.DownloadCancelled |
Download was cancelled by the user. |
WebEngineDownloadItem.DownloadInterrupted |
Download has been interrupted (by the server or because of lost connectivity). |
totalBytes : int▲
Holds the total amount of data to download in bytes.
-1 means the total size is unknown.
[read-only, since QtWebEngine 1.8] view : WebEngineView▲
Returns the view the download was requested on. If the download was not triggered by content in a view, nullptr is returned.
This property was introduced in QtWebEngine 1.8.
See Also▲
See also WebEngineView
Method Documentation▲
void accept()▲
Accepts the 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▲
See also state
void cancel()▲
Cancels the 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▲
See also state
[since QtWebEngine 1.6] void pause()▲
Pauses the download.
Has no effect if the state is not DownloadInProgress. Does not change the state.
This method was introduced in QtWebEngine 1.6.
See Also▲
[since QtWebEngine 1.6] void resume()▲
Obsolete Members for WebEngineDownloadItem▲
The following members of QML type WebEngineDownloadItem are deprecated. We strongly advise against using them in new code.
Obsolete Property Documentation▲
[read-only, since QtWebEngine 1.4] type : enumeration▲
This property is deprecated. We strongly advise against using it in new code.
Describes the requested download's type.
This property works unreliably, except for SavePage downloads. Use isSavePageDownload instead.
Constant |
Description |
---|---|
WebEngineDownloadItem.Attachment |
The web server's response includes a Content-Disposition header with the attachment directive. If Content-Disposition is present in the reply, the web server is indicating that the client should prompt the user to save the content regardless of the content type. See RFC 2616 section 19.5.1 for details. |
WebEngineDownloadItem.DownloadAttribute |
The user clicked a link with the download attribute. |
WebEngineDownloadItem.UserRequested |
The user initiated the download, for example by selecting a web action. |
WebEngineDownloadItem.SavePage |
Saving of the current page was requested (for example by the WebEngineView.SavePage web action). |
This property was introduced in QtWebEngine 1.4.