QWebEngineDownloadItemclass provides information about a download. 更多 …
def
downloadDirectory
()
def
downloadFileName
()
def
id
()
def
interruptReason
()
def
interruptReasonString
()
def
isFinished
()
def
isPaused
()
def
isSavePageDownload
()
def
mimeType
()
def
page
()
def
path
()
def
receivedBytes
()
def
savePageFormat
()
def
setDownloadDirectory
(directory)
def
setDownloadFileName
(fileName)
def
setPath
(path)
def
setSavePageFormat
(format)
def
state
()
def
suggestedFileName
()
def
totalBytes
()
def
type
()
def
url
()
def
downloadProgress
(bytesReceived, bytesTotal)
def
finished
()
def
isPausedChanged
(isPaused)
def
stateChanged
(state)
QWebEngineDownloadItemmodels 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 thedownloadRequestedsignal together with a newly createdQWebEngineDownloadItem. The application can then examine this item and decide whether to accept it or not. A signal handler must explicitly callaccept()on the item for Qt WebEngine to actually start downloading and writing data to disk. If no signal handler callsaccept(), then the download request will be automatically rejected and nothing will be written to disk.注意
某些特性,如设置文件保存路径和文件名 (见
downloadDirectory()anddownloadFileName()), can only be changed before callingaccept().
所有项均保证有效,在发出期间为
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
|
|
QWebEngineDownloadItem.DownloadAttribute |
The user clicked a link with the
|
|
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
|
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
(
)
¶
返回下载为什么被中断的原因。
PySide2.QtWebEngineWidgets.QWebEngineDownloadItem.
interruptReasonString
(
)
¶
unicode
返回人类可读的中断下载原因的描述。
另请参阅
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
(
)
¶
返回请求下载的页面。若下载不由页面内容所触发,
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.
另请参阅
PySide2.QtWebEngineWidgets.QWebEngineDownloadItem.
pause
(
)
¶
暂停下载。
没有影响,若状态不是
DownloadInProgress
。不改变状态。
另请参阅
PySide2.QtWebEngineWidgets.QWebEngineDownloadItem.
receivedBytes
(
)
¶
qint64
返回到目前为止已下载的数据数量 (以字节为单位)。
-1
意味着尺寸未知。
PySide2.QtWebEngineWidgets.QWebEngineDownloadItem.
resume
(
)
¶
再继续当前下载,若它被暂停或中断。
没有影响,若状态不是
DownloadInProgress
or
DownloadInterrupted
。不改变状态。
另请参阅
PySide2.QtWebEngineWidgets.QWebEngineDownloadItem.
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.
另请参阅
PySide2.QtWebEngineWidgets.QWebEngineDownloadItem.
setSavePageFormat
(
format
)
¶
format
–
SavePageFormat
设置
format
为网页保存,若这是网页下载请求。
PySide2.QtWebEngineWidgets.QWebEngineDownloadItem.
state
(
)
¶
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
(
)
¶
注意
此函数被弃用。
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.