WebEngineDownloadRequest QML Type

Provides information about a download. More...

Import Statement: import QtWebEngine
Instantiates: QWebEngineDownloadRequest

Properties

Methods

Detailed Description

WebEngineDownloadRequest 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 WebEngineDownloadRequest. 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, 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 WebEngineProfile, WebEngineProfile::downloadRequested, and WebEngineProfile::downloadFinished.

Property Documentation

downloadDirectory : string

Holds the full target path without file name where data is being downloaded to.

The download directory can only be set in the downloadRequested handler before the download is accepted.

See also WebEngineProfile::downloadRequested() and accept().


downloadFileName : string

Holds the name of the file to which data is being downloaded.

The download file name can only be set in the downloadRequested handler before the download is accepted.

See also WebEngineProfile::downloadRequested() and accept().


[read-only] id : int

Holds the download item's ID.


[read-only] interruptReason : enumeration

Returns the reason why the download was interrupted:

ConstantDescription
WebEngineDownloadRequest.NoReasonUnknown reason or not interrupted.
WebEngineDownloadRequest.FileFailedGeneral file operation failure.
WebEngineDownloadRequest.FileAccessDeniedThe file cannot be written locally, due to access restrictions.
WebEngineDownloadRequest.FileNoSpaceInsufficient space on the target drive.
WebEngineDownloadRequest.FileNameTooLongThe directory or file name is too long.
WebEngineDownloadRequest.FileTooLargeThe file size exceeds the file system limitation.
WebEngineDownloadRequest.FileVirusInfectedThe file is infected with a virus.
WebEngineDownloadRequest.FileTransientErrorTemporary problem (for example the file is in use, out of memory, or too many files are opened at once).
WebEngineDownloadRequest.FileBlockedThe file was blocked due to local policy.
WebEngineDownloadRequest.FileSecurityCheckFailedAn attempt to check the safety of the download failed due to unexpected reasons.
WebEngineDownloadRequest.FileTooShortAn attempt was made to seek past the end of a file when opening a file (as part of resuming a previously interrupted download).
WebEngineDownloadRequest.FileHashMismatchThe partial file did not match the expected hash.
WebEngineDownloadRequest.NetworkFailedGeneral network failure.
WebEngineDownloadRequest.NetworkTimeoutThe network operation has timed out.
WebEngineDownloadRequest.NetworkDisconnectedThe network connection has been terminated.
WebEngineDownloadRequest.NetworkServerDownThe server has gone down.
WebEngineDownloadRequest.NetworkInvalidRequestThe network request was invalid (for example, the original or redirected URL is invalid, has an unsupported scheme, or is disallowed by policy).
WebEngineDownloadRequest.ServerFailedGeneral server failure.
WebEngineDownloadRequest.ServerBadContentThe server does not have the requested data.
WebEngineDownloadRequest.ServerUnauthorizedThe server did not authorize access to the resource.
WebEngineDownloadRequest.ServerCertProblemA problem with the server certificate occurred.
WebEngineDownloadRequest.ServerForbiddenAccess forbidden by the server.
WebEngineDownloadRequest.ServerUnreachableUnexpected server response (might indicate that the responding server may not be the intended server).
WebEngineDownloadRequest.UserCanceledThe user canceled the download.

See also interruptReasonString.


[read-only] interruptReasonString : string

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

See also interruptReason.


[read-only] isFinished : bool

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


[read-only] isPaused : bool

Whether this download is paused.

See also pause and resume.


[read-only] isSavePageDownload : bool

Whether this is a download request for saving a web page or a file.

See also savePageFormat.


[read-only] mimeType : string

Holds the MIME type of the download.


[read-only] receivedBytes : int

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


savePageFormat : enumeration

Describes the format that is used to save a web page.

ConstantDescription
WebEngineDownloadRequest.UnknownSaveFormatThis is not a request for downloading a complete web page.
WebEngineDownloadRequest.SingleHtmlSaveFormatThe page is saved as a single HTML page. Resources such as images are not saved.
WebEngineDownloadRequest.CompleteHtmlSaveFormatThe page is saved as a complete HTML page, for example a directory containing the single HTML page and the resources.
WebEngineDownloadRequest.MimeHtmlSaveFormatThe page is saved as a complete web page in the MIME HTML format.

[read-only] state : enumeration

Describes the state of the download:

ConstantDescription
WebEngineDownloadRequest.DownloadRequestedDownload has been requested, but it has not been accepted yet.
WebEngineDownloadRequest.DownloadInProgressDownload is in progress.
WebEngineDownloadRequest.DownloadCompletedDownload completed successfully.
WebEngineDownloadRequest.DownloadCancelledDownload was cancelled by the user.
WebEngineDownloadRequest.DownloadInterruptedDownload has been interrupted (by the server or because of lost connectivity).

[read-only] suggestedFileName : string

Returns the suggested file name.


[read-only] totalBytes : int

Holds the total amount of data to download in bytes.

-1 means the total size is unknown.


[read-only] url : url

Returns the download's origin URL.


[read-only] view : WebEngineView

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

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 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 state.


void pause()

Pauses the download.

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

See also resume and isPaused.


void resume()

Resumes the 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 pause and isPaused.


© 2024 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.