QWebEngineDownloadItem

QWebEngineDownloadItem class provides information about a download. 更多

Inheritance diagram of PySide2.QtWebEngineWidgets.QWebEngineDownloadItem

详细描述

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

通常,下载由网页上的用户交互触发。它是 QWebEngineProfile ‘s responsibility to notify the application of new download requests, which it does by emitting the downloadRequested signal together with a newly created QWebEngineDownloadItem . 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.

注意

某些特性,如设置文件保存路径和文件名 (见 downloadDirectory() and downloadFileName() ), can only be changed before calling accept() .

对象生命周期

所有项均保证有效,在发出期间为 downloadRequested 信号。若 accept() is not 被任何信号处理程序所调用,则项会被删除 immediately 在信号发出之后。这意味着应用程序 不必 对拒绝下载项保持引用。它也意味着应用程序不应对此信号使用队列连接。

accept() is 被信号处理程序所调用,那么 QWebEngineProfile 将获得项的所有权。不管怎样,应用程序随时删除项是安全的,除了在处理期间为 downloadRequested 信号。 QWebEngineProfile 是长期活着的对象,实际上,推荐应用程序删除它不再感兴趣的任何项。

注意

从 5.12.2 起删除项也会被自动取消下载,但为了可移植性,推荐在删除之前手动取消。

网页下载

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 )。要检查下载的是文件还是网页,使用 isSavePageDownload .

PySide2.QtWebEngineWidgets.QWebEngineDownloadItem. DownloadState

此枚举描述下载的状态:

常量

描述

QWebEngineDownloadItem.DownloadRequested

下载已请求,但尚未接受。

QWebEngineDownloadItem.DownloadInProgress

下载正在进行中。

QWebEngineDownloadItem.DownloadCompleted

下载成功完成。

QWebEngineDownloadItem.DownloadCancelled

下载已被取消。

QWebEngineDownloadItem.DownloadInterrupted

下载已被中断 (由服务器或由于丢失连接)。

PySide2.QtWebEngineWidgets.QWebEngineDownloadItem. SavePageFormat

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

常量

描述

QWebEngineDownloadItem.UnknownSaveFormat

这不是下载完整网页的请求。

QWebEngineDownloadItem.SingleHtmlSaveFormat

页面被另存为单 HTML 页面。图像等资源不被保存。

QWebEngineDownloadItem.CompleteHtmlSaveFormat

页面被另存为完整 HTML 页面,例如:目录包含单 HTML 页面和资源。

QWebEngineDownloadItem.MimeHtmlSaveFormat

页面以 MIME HTML 格式,被另存为完整网页。

PySide2.QtWebEngineWidgets.QWebEngineDownloadItem. DownloadInterruptReason

描述下载为什么被中断的原因:

常量

描述

QWebEngineDownloadItem.NoReason

未知原因或未中断。

QWebEngineDownloadItem.FileFailed

常规文件操作失败。

QWebEngineDownloadItem.FileAccessDenied

文件无法在本地写入,由于访问限定。

QWebEngineDownloadItem.FileNoSpace

目标驱动器空间不足。

QWebEngineDownloadItem.FileNameTooLong

目录或文件名太长。

QWebEngineDownloadItem.FileTooLarge

文件尺寸超过文件系统限制。

QWebEngineDownloadItem.FileVirusInfected

文件被病毒感染。

QWebEngineDownloadItem.FileTransientError

临时问题 (例如:文件在使用中、内存不足或一次打开太多文件)。

QWebEngineDownloadItem.FileBlocked

文件被阻塞由于本地策略。

QWebEngineDownloadItem.FileSecurityCheckFailed

尝试检查下载的安全性失败,由于意外原因。

QWebEngineDownloadItem.FileTooShort

尝试寻址超出文件末尾,当打开文件时 (作为再继续先前被中断下载的一部分)。

QWebEngineDownloadItem.FileHashMismatch

部分文件不匹配预期哈希。

QWebEngineDownloadItem.NetworkFailed

常规网络故障。

QWebEngineDownloadItem.NetworkTimeout

网络操作已超时。

QWebEngineDownloadItem.NetworkDisconnected

网络连接已被终止。

QWebEngineDownloadItem.NetworkServerDown

服务器宕机。

QWebEngineDownloadItem.NetworkInvalidRequest

网络请求无效 (例如:原始或重定向 URL 无效,方案不受支持或被策略禁止)。

QWebEngineDownloadItem.ServerFailed

常规服务器故障。

QWebEngineDownloadItem.ServerBadContent

服务器没有请求的数据。

QWebEngineDownloadItem.ServerUnauthorized

服务器未授权访问资源。

QWebEngineDownloadItem.ServerCertProblem

服务器证书发生问题。

QWebEngineDownloadItem.ServerForbidden

访问被服务器禁止。

QWebEngineDownloadItem.ServerUnreachable

意外服务器响应 (可能指示响应服务器,可能不是企图服务器)。

QWebEngineDownloadItem.UserCanceled

用户取消下载。

PySide2.QtWebEngineWidgets.QWebEngineDownloadItem. DownloadType

Describes the requested download’s type.

常量

描述

QWebEngineDownloadItem.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 了解细节。

QWebEngineDownloadItem.DownloadAttribute

The user clicked a link with the download 属性。

QWebEngineDownloadItem.UserRequested

The user initiated the download, for example by selecting a web action.

QWebEngineDownloadItem.SavePage

Saving of the current page was requested (for example by the SavePage web action).

PySide2.QtWebEngineWidgets.QWebEngineDownloadItem. accept ( )

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

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

PySide2.QtWebEngineWidgets.QWebEngineDownloadItem. cancel ( )

取消当前下载。

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

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

PySide2.QtWebEngineWidgets.QWebEngineDownloadItem. downloadDirectory ( )
返回类型

unicode

返回下载目录路径。

PySide2.QtWebEngineWidgets.QWebEngineDownloadItem. downloadFileName ( )
返回类型

unicode

返回要下载文件的文件名。

PySide2.QtWebEngineWidgets.QWebEngineDownloadItem. downloadProgress ( bytesReceived , bytesTotal )
参数
  • bytesReceived qint64

  • bytesTotal qint64

PySide2.QtWebEngineWidgets.QWebEngineDownloadItem. finished ( )
PySide2.QtWebEngineWidgets.QWebEngineDownloadItem. id ( )
返回类型

quint32

Returns the download item’s ID.

PySide2.QtWebEngineWidgets.QWebEngineDownloadItem. interruptReason ( )
返回类型

DownloadInterruptReason

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

PySide2.QtWebEngineWidgets.QWebEngineDownloadItem. interruptReasonString ( )
返回类型

unicode

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

另请参阅

interruptReason()

PySide2.QtWebEngineWidgets.QWebEngineDownloadItem. isFinished ( )
返回类型

bool

返回此下载是否完成 (完成、取消或非再继续中断状态)。

PySide2.QtWebEngineWidgets.QWebEngineDownloadItem. isPaused ( )
返回类型

bool

返回此下载是否被暂停。

PySide2.QtWebEngineWidgets.QWebEngineDownloadItem. isPausedChanged ( isPaused )
参数

isPaused bool

PySide2.QtWebEngineWidgets.QWebEngineDownloadItem. isSavePageDownload ( )
返回类型

bool

返回 true 若这是用于保存网页的下载请求。

PySide2.QtWebEngineWidgets.QWebEngineDownloadItem. mimeType ( )
返回类型

unicode

返回下载的 MIME 类型。

PySide2.QtWebEngineWidgets.QWebEngineDownloadItem. page ( )
返回类型

QWebEnginePage

返回请求下载的页面。若下载不由页面内容所触发, nullptr 被返回。

PySide2.QtWebEngineWidgets.QWebEngineDownloadItem. path ( )
返回类型

unicode

注意

此函数被弃用。

使用 suggestedFileName() , downloadDirectory() ,和 downloadFileName() 代替。

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

另请参阅

setPath()

PySide2.QtWebEngineWidgets.QWebEngineDownloadItem. pause ( )

暂停下载。

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

PySide2.QtWebEngineWidgets.QWebEngineDownloadItem. receivedBytes ( )
返回类型

qint64

返回到目前为止已下载的数据数量 (以字节为单位)。

-1 意味着尺寸未知。

PySide2.QtWebEngineWidgets.QWebEngineDownloadItem. resume ( )

再继续当前下载,若它被暂停或中断。

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

PySide2.QtWebEngineWidgets.QWebEngineDownloadItem. savePageFormat ( )
返回类型

SavePageFormat

返回保存网页的格式,如果这是用于网页的下载请求。

PySide2.QtWebEngineWidgets.QWebEngineDownloadItem. setDownloadDirectory ( directory )
参数

directory – unicode

directory 作为要下载文件的目录路径。

下载目录才可以被设置为响应 downloadRequested() signal before the download is accepted. Past that point, this function has no effect on the download item’s state.

PySide2.QtWebEngineWidgets.QWebEngineDownloadItem. setDownloadFileName ( fileName )
参数

fileName – unicode

fileName 作为要下载文件的文件名。

下载文件名才可以被设置为响应 downloadRequested() signal before the download is accepted. Past that point, this function has no effect on the download item’s state.

PySide2.QtWebEngineWidgets.QWebEngineDownloadItem. setPath ( path )
参数

path – unicode

注意

此函数被弃用。

使用 setDownloadDirectory() and setDownloadFileName() 代替。

Sets the full target path to download the file to.

path should also include the file name. The download 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.

另请参阅

path()

PySide2.QtWebEngineWidgets.QWebEngineDownloadItem. setSavePageFormat ( format )
参数

format SavePageFormat

设置 format 为网页保存,若这是网页下载请求。

PySide2.QtWebEngineWidgets.QWebEngineDownloadItem. state ( )
返回类型

DownloadState

Returns the download item’s current state.

另请参阅

DownloadState

PySide2.QtWebEngineWidgets.QWebEngineDownloadItem. stateChanged ( state )
参数

state DownloadState

PySide2.QtWebEngineWidgets.QWebEngineDownloadItem. suggestedFileName ( )
返回类型

unicode

返回建议的文件名。

PySide2.QtWebEngineWidgets.QWebEngineDownloadItem. totalBytes ( )
返回类型

qint64

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

-1 意味着尺寸未知。

PySide2.QtWebEngineWidgets.QWebEngineDownloadItem. type ( )
返回类型

DownloadType

注意

此函数被弃用。

Returns the requested download’s type.

注意

This property works unreliably, except for SavePage downloads. Use isSavePageDownload() 代替。

PySide2.QtWebEngineWidgets.QWebEngineDownloadItem. url ( )
返回类型

QUrl

Returns the download’s origin URL.