WebEngineDownloadItem QML 类型

提供关于下载的信息。 更多...

导入语句: 导入 QtWebEngine 1.10
Since: QtWebEngine 1.1

特性

方法

详细描述

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.

通常,下载由网页上的用户交互触发。它是 WebEngineProfile 的职责,通知应用程序有新的下载请求,通过发射 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() .

对象生命周期

所有项均保证有效,在发出期间为 downloadRequested 信号。若 accept() is not 被任何信号处理程序所调用,则项会被删除 immediately 在信号发出之后。这意味着应用程序 不必 keep references to rejected download items.

网页下载

除正常文件下载 (简单地从网络检索一些原生字节并把它们写入磁盘) 外,Qt WebEngine 还支持保存完整网页,涉及剖析页面的 HTML、下载任何从属资源及把潜在的一切打包进特殊文件格式 ( savePageFormat )。要检查下载的是文件还是网页,使用 isSavePageDownload .

另请参阅 WebEngineProfile , WebEngineProfile::downloadRequested ,和 WebEngineProfile::downloadFinished .

特性文档编制

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.

该特性在 QtWebEngine 1.10 引入。

另请参阅 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.

该特性在 QtWebEngine 1.10 引入。

另请参阅 WebEngineProfile::downloadRequested() and accept() .


id : int

保存下载项的 ID。


[read-only] interruptReason : enumeration

返回下载为什么中断的原因:

常量 描述
WebEngineDownloadItem.NoReason 未知原因或未中断。
WebEngineDownloadItem.FileFailed 常规文件操作故障。
WebEngineDownloadItem.FileAccessDenied 文件无法在本地写入,由于访问限定。
WebEngineDownloadItem.FileNoSpace 目标驱动器空间不足。
WebEngineDownloadItem.FileNameTooLong 目录或文件名太长。
WebEngineDownloadItem.FileTooLarge 文件大小超过文件系统限制。
WebEngineDownloadItem.FileVirusInfected 文件被病毒感染。
WebEngineDownloadItem.FileTransientError 临时问题 (例如:文件在使用中、内存不足或一次打开太多文件)。
WebEngineDownloadItem.FileBlocked 文件被阻塞由于本地策略。
WebEngineDownloadItem.FileSecurityCheckFailed 试图检查下载失败的安全性,由于意外原因。
WebEngineDownloadItem.FileTooShort 尝试寻址超出文件末尾,当打开文件时 (作为再继续先前被中断下载的一部分)。
WebEngineDownloadItem.FileHashMismatch 部分文件不匹配预期哈希。
WebEngineDownloadItem.NetworkFailed 常规网络故障。
WebEngineDownloadItem.NetworkTimeout 网络操作已超时。
WebEngineDownloadItem.NetworkDisconnected 网络连接已被终止。
WebEngineDownloadItem.NetworkServerDown 服务器宕机。
WebEngineDownloadItem.NetworkInvalidRequest 网络请求无效 (例如:原始或重定向 URL 无效,方案不受支持或被策略禁止)。
WebEngineDownloadItem.ServerFailed 常规服务器故障。
WebEngineDownloadItem.ServerBadContent 服务器没有请求的数据。
WebEngineDownloadItem.ServerUnauthorized 服务器未授权访问资源。
WebEngineDownloadItem.ServerCertProblem 服务器证书发生问题。
WebEngineDownloadItem.ServerForbidden 访问被服务器禁止。
WebEngineDownloadItem.ServerUnreachable 意外服务器响应 (可能指示响应服务器,可能不是企图服务器)。
WebEngineDownloadItem.UserCanceled 用户取消下载。

This property was introduced in QtWebEngine 1.5.

另请参阅 interruptReasonString .


interruptReasonString : string

返回人类可读的中断下载原因的描述。

This property was introduced in QtWebEngine 1.5.

另请参阅 interruptReason .


[read-only] isFinished : bool

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

This property was introduced in QtWebEngine 1.6.


[read-only] isPaused : bool

Whether this download is paused.

This property was introduced in QtWebEngine 1.6.

另请参阅 pause and resume .


[read-only] isSavePageDownload : bool

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

该特性在 QtWebEngine 1.7 引入。

另请参阅 savePageFormat .


mimeType : string

保存下载的 MIME 类型。

This property was introduced in QtWebEngine 1.2.


receivedBytes : int

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


savePageFormat : enumeration

描述用于保存网页的格式。

常量 描述
WebEngineDownloadItem.UnknownSaveFormat 这不是下载完整网页的请求。
WebEngineDownloadItem.SingleHtmlSaveFormat 页面被另存为单 HTML 页面。图像等资源不被保存。
WebEngineDownloadItem.CompleteHtmlSaveFormat 页面被另存为完整 HTML 页面,例如:目录包含单 HTML 页面和资源。
WebEngineDownloadItem.MimeHtmlSaveFormat 页面以 MIME HTML 格式,被另存为完整网页。

该特性在 QtWebEngine 1.3 引入。


state : enumeration

描述下载的状态:

常量 描述
WebEngineDownloadItem.DownloadRequested 已请求下载,但尚未被接受。
WebEngineDownloadItem.DownloadInProgress 下载正在进行中。
WebEngineDownloadItem.DownloadCompleted 下载成功完成。
WebEngineDownloadItem.DownloadCancelled 下载被用户取消。
WebEngineDownloadItem.DownloadInterrupted 下载已被中断 (由服务器或由于丢失连接)。

suggestedFileName : string

返回建议的文件名。

该特性在 QtWebEngine 1.10 引入。


totalBytes : int

保存要下载的数据总量 (以字节为单位)。

-1 意味着总尺寸未知。


[read-only] url : url

返回下载的原始 URL。

该特性在 QtWebEngine 1.10 引入。


[read-only] view : WebEngineView

Returns the view the download was requested on. If the download was not triggered by content in a view, nullptr 被返回。

This property was introduced in QtWebEngine 1.8.

另请参阅 WebEngineView .


方法文档编制

void accept ()

接受下载请求,将开始下载。

若项在 DownloadRequested 状态,那么它将过渡到 DownloadInProgress 状态,且下载会开始。若项在任何其它状态,则什么都不会发生。

另请参阅 state .


void cancel ()

取消下载。

若项在 DownloadInProgress 状态,那么它将过渡到 DownloadCancelled 状态,下载会停止,且部分下载文件会从磁盘被删除。

若项在 DownloadCompleted 状态,则什么都不会发生。若项在任何其它状态,则它会过渡到 DownloadCancelled 状态,没有进一步影响。

另请参阅 state .


void pause ()

暂停下载。

没有影响,若状态不是 DownloadInProgress 。不改变状态。

This method was introduced in QtWebEngine 1.6.

另请参阅 resume and isPaused .


void resume ()

Resumes the download if it was paused or interrupted.

没有影响,若状态不是 DownloadInProgress or DownloadInterrupted 。不改变状态。

This method was introduced in QtWebEngine 1.6.

另请参阅 pause and isPaused .