The QWebEngineDownloadItem class provides information about a download. 更多...
| 頭: | #include <QWebEngineDownloadItem> |
| qmake: | QT += webenginewidgets |
| Since: | Qt 5.5 |
| 繼承: | QObject |
| enum | DownloadInterruptReason { NoReason, FileFailed, FileAccessDenied, FileNoSpace, ..., UserCanceled } |
| enum | DownloadState { DownloadRequested, DownloadInProgress, DownloadCompleted, DownloadCancelled, DownloadInterrupted } |
| enum | SavePageFormat { UnknownSaveFormat, SingleHtmlSaveFormat, CompleteHtmlSaveFormat, MimeHtmlSaveFormat } |
| quint32 | id () const |
| QWebEngineDownloadItem::DownloadInterruptReason | interruptReason () const |
| QString | interruptReasonString () const |
| bool | isFinished () const |
| bool | isPaused () const |
| bool | isSavePageDownload () const |
| QString | mimeType () const |
| QWebEnginePage * | page () const |
| QString | path () const |
| qint64 | receivedBytes () const |
| QWebEngineDownloadItem::SavePageFormat | savePageFormat () const |
| void | setPath (QString path ) |
| void | setSavePageFormat (QWebEngineDownloadItem::SavePageFormat format ) |
| QWebEngineDownloadItem::DownloadState | state () const |
| qint64 | totalBytes () const |
| QUrl | url () const |
| void | accept () |
| void | cancel () |
| void | pause () |
| void | resume () |
| void | downloadProgress (qint64 bytesReceived , qint64 bytesTotal ) |
| void | finished () |
| void | isPausedChanged (bool isPaused ) |
| void | stateChanged (QWebEngineDownloadItem::DownloadState state ) |
| const QMetaObject | staticMetaObject |
The QWebEngineDownloadItem class provides information about a download.
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 的職責,通知應用程序有新的下載請求,通過發射 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 () 在項,以便 Qt WebEngine 實際開始下載並把數據寫入磁盤。若沒有信號處理程序調用 accept (),那麼下載請求將被自動拒絕,且什麼都不會被寫入磁盤。
注意: Some properties, like the path under which the file will be saved, can only be changed before calling accept ().
所有項均保證有效,在發齣期間為 downloadRequested 信號。若 accept () 是 not 被任何信號處理程序所調用,則項會被刪除 immediately 在信號發齣之後。這意味著應用程序 不必 對拒絕下載項保持引用。它也意味著應用程序不應對此信號使用隊列連接。
若 accept () is 被信號處理程序所調用,那麼 QWebEngineProfile 將獲得項的所有權。不管怎樣,應用程序隨時刪除項是安全的,除瞭在處理期間為 downloadRequested 信號。 QWebEngineProfile 是長期存活對象,事實上,推薦應用程序刪除它不再感興趣的任何項。
注意: 從 5.12.2 起刪除項也會被自動取消下載,但為瞭可移植性,推薦在刪除之前手動取消。
除正常文件下載 (簡單地從網絡檢索一些原生字節並把它們寫入磁盤) 外,Qt WebEngine 還支持保存完整網頁,涉及剖析頁麵的 HTML、下載任何從屬資源及把潛在的一切打包進特殊文件格式 ( savePageFormat )。要檢查下載的是文件還是網頁,使用 isSavePageDownload .
另請參閱 QWebEngineProfile , QWebEngineProfile::downloadRequested , QWebEnginePage::download ,和 QWebEnginePage::save .
描述下載為什麼被中斷的原因:
| 常量 | 值 | 描述 |
|---|---|---|
QWebEngineDownloadItem::NoReason
|
0
|
未知原因或未中斷。 |
QWebEngineDownloadItem::FileFailed
|
1
|
常規文件操作故障。 |
QWebEngineDownloadItem::FileAccessDenied
|
2
|
文件無法在本地寫入,由於訪問限定。 |
QWebEngineDownloadItem::FileNoSpace
|
3
|
目標驅動器空間不足。 |
QWebEngineDownloadItem::FileNameTooLong
|
5
|
目錄或文件名太長。 |
QWebEngineDownloadItem::FileTooLarge
|
6
|
文件大小超過文件係統限製。 |
QWebEngineDownloadItem::FileVirusInfected
|
7
|
文件被病毒感染。 |
QWebEngineDownloadItem::FileTransientError
|
10
|
臨時問題 (例如:文件在使用中、內存不足或一次打開太多文件)。 |
QWebEngineDownloadItem::FileBlocked
|
11
|
文件被阻塞由於本地策略。 |
QWebEngineDownloadItem::FileSecurityCheckFailed
|
12
|
試圖檢查下載失敗的安全性,由於意外原因。 |
QWebEngineDownloadItem::FileTooShort
|
13
|
嘗試尋址超齣文件末尾,當打開文件時 (作為再繼續先前被中斷下載的一部分)。 |
QWebEngineDownloadItem::FileHashMismatch
|
14
|
部分文件不匹配預期哈希。 |
QWebEngineDownloadItem::NetworkFailed
|
20
|
常規網絡故障。 |
QWebEngineDownloadItem::NetworkTimeout
|
21
|
網絡操作已超時。 |
QWebEngineDownloadItem::NetworkDisconnected
|
22
|
網絡連接已被終止。 |
QWebEngineDownloadItem::NetworkServerDown
|
23
|
服務器宕機。 |
QWebEngineDownloadItem::NetworkInvalidRequest
|
24
|
網絡請求無效 (例如:原始或重定嚮 URL 無效,方案不受支持或被策略禁止)。 |
QWebEngineDownloadItem::ServerFailed
|
30
|
常規服務器故障。 |
QWebEngineDownloadItem::ServerBadContent
|
33
|
服務器沒有請求的數據。 |
QWebEngineDownloadItem::ServerUnauthorized
|
34
|
服務器未授權訪問資源。 |
QWebEngineDownloadItem::ServerCertProblem
|
35
|
服務器證書發生問題。 |
QWebEngineDownloadItem::ServerForbidden
|
36
|
訪問被服務器禁止。 |
QWebEngineDownloadItem::ServerUnreachable
|
37
|
意外服務器響應 (可能指示響應服務器,可能不是企圖服務器)。 |
QWebEngineDownloadItem::UserCanceled
|
40
|
用戶取消下載。 |
該枚舉在 Qt 5.9 引入或被修改。
此枚舉描述下載的狀態:
| 常量 | 值 | 描述 |
|---|---|---|
QWebEngineDownloadItem::DownloadRequested
|
0
|
下載已請求,但尚未接受。 |
QWebEngineDownloadItem::DownloadInProgress
|
1
|
下載正在進行中。 |
QWebEngineDownloadItem::DownloadCompleted
|
2
|
下載成功完成。 |
QWebEngineDownloadItem::DownloadCancelled
|
3
|
下載已被取消。 |
QWebEngineDownloadItem::DownloadInterrupted
|
4
|
下載已被中斷 (由服務器或由於丟失連接)。 |
此枚舉描述用於保存網頁的格式。
| 常量 | 值 | 描述 |
|---|---|---|
QWebEngineDownloadItem::UnknownSaveFormat
|
-1
|
這不是下載完整網頁的請求。 |
QWebEngineDownloadItem::SingleHtmlSaveFormat
|
0
|
頁麵被另存為單 HTML 頁麵。圖像等資源不被保存。 |
QWebEngineDownloadItem::CompleteHtmlSaveFormat
|
1
|
頁麵被另存為完整 HTML 頁麵,例如:目錄包含單 HTML 頁麵和資源。 |
QWebEngineDownloadItem::MimeHtmlSaveFormat
|
2
|
以 MIME HTML 格式,把頁麵另存為完整網頁。 |
該枚舉在 Qt 5.7 引入或被修改。
[slot]
void
QWebEngineDownloadItem::
accept
()
接受當前下載請求,將開始下載。
若項在 DownloadRequested 狀態,那麼它將過渡到 DownloadInProgress 狀態,且下載會開始。若項在任何其它狀態,則什麼都不會發生。
另請參閱 finished () 和 stateChanged ().
[slot]
void
QWebEngineDownloadItem::
cancel
()
取消當前下載。
若項在 DownloadInProgress 狀態,那麼它將過渡到 DownloadCancelled 狀態,下載會停止,且部分下載文件會從磁盤被刪除。
若項在 DownloadCompleted 狀態,則什麼都不會發生。若項在任何其它狀態,則它會過渡到 DownloadCancelled 狀態,沒有進一步影響。
另請參閱 finished () 和 stateChanged ().
[signal]
void
QWebEngineDownloadItem::
downloadProgress
(
qint64
bytesReceived
,
qint64
bytesTotal
)
此信號被發射,以指示下載請求的進度。
The
bytesReceived
參數指示接收字節數,而
bytesTotal
指示期望要下載的總字節數。若要下載的文件大小不知道,
bytesTotal
會為 0。
另請參閱 totalBytes () 和 receivedBytes ().
[signal]
void
QWebEngineDownloadItem::
finished
()
此信號被發射當下載完成時。
另請參閱 state () 和 isFinished ().
返迴下載項 ID。
返迴下載為什麼被中斷的原因。
該函數在 Qt 5.9 引入。
另請參閱 interruptReasonString ().
返迴人類可讀的中斷下載原因的描述。
該函數在 Qt 5.9 引入。
另請參閱 interruptReason ().
返迴此下載是否完成 (完成、取消或非再繼續中斷狀態)。
返迴此下載是否被暫停。
[signal]
void
QWebEngineDownloadItem::
isPausedChanged
(
bool
isPaused
)
此信號發射,每當 isPaused 改變。
該函數在 Qt 5.10 引入。
返迴
true
若這是用於保存網頁的下載請求。
該函數在 Qt 5.11 引入。
另請參閱 savePageFormat () 和 setSavePageFormat ().
返迴下載的 MIME 類型。
該函數在 Qt 5.6 引入。
返迴請求下載的頁麵。若下載不由頁麵內容所觸發,
nullptr
被返迴。
該函數在 Qt 5.12 引入。
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 ().
[slot]
void
QWebEngineDownloadItem::
pause
()
暫停下載。
不起作用,若狀態不是 DownloadInProgress 。不改變狀態。
該函數在 Qt 5.10 引入。
返迴到目前為止已下載的數據數量 (以字節為單位)。
-1
意味著尺寸未知。
[slot]
void
QWebEngineDownloadItem::
resume
()
再繼續當前下載,若它被暫停或中斷。
不起作用,若狀態不是 DownloadInProgress or DownloadInterrupted 。不改變狀態。
該函數在 Qt 5.10 引入。
另請參閱 pause (), isPaused (),和 state ().
返迴保存網頁的格式,若這是針對網頁的下載請求。
該函數在 Qt 5.7 引入。
另請參閱 setSavePageFormat () 和 isSavePageDownload ().
Sets the full target path to download the file to.
The path should also include the file name. The download path can only be set in response to the QWebEngineProfile::downloadRequested () 信號在接受下載前。此後,此函數對下載項狀態不起作用。
另請參閱 path ().
設置 format 為網頁保存,若這是網頁下載請求。
該函數在 Qt 5.7 引入。
另請參閱 savePageFormat () 和 isSavePageDownload ().
返迴下載項的當前狀態。
另請參閱 DownloadState .
[signal]
void
QWebEngineDownloadItem::
stateChanged
(
QWebEngineDownloadItem::DownloadState
state
)
此信號發射每當下載的 state 改變。
另請參閱 state () 和 DownloadState .
返迴要下載的數據總數量 (以字節為單位)。
-1
意味著尺寸未知。
返迴下載的原始 URL。