QWebEngineDownloadRequest 類

QWebEngineDownloadRequest 類提供下載的有關信息。 更多...

頭: #include <QWebEngineDownloadRequest>
CMake: find_package(Qt6 REQUIRED COMPONENTS WebEngineCore)
target_link_libraries(mytarget PRIVATE Qt6::WebEngineCore)
qmake: QT += webenginecore
在 QML: WebEngineDownloadRequest
繼承: QObject

公共類型

enum DownloadInterruptReason { NoReason, FileFailed, FileAccessDenied, FileNoSpace, FileNameTooLong, …, UserCanceled }
enum DownloadState { DownloadRequested, DownloadInProgress, DownloadCompleted, DownloadCancelled, DownloadInterrupted }
enum SavePageFormat { UnknownSaveFormat, SingleHtmlSaveFormat, CompleteHtmlSaveFormat, MimeHtmlSaveFormat }

特性

公共函數

QString downloadDirectory () const
QString downloadFileName () const
quint32 id () const
QWebEngineDownloadRequest::DownloadInterruptReason interruptReason () const
QString interruptReasonString () const
bool isFinished () const
bool isPaused () const
bool isSavePageDownload () const
QString mimeType () const
QWebEnginePage * page () const
qint64 receivedBytes () const
QWebEngineDownloadRequest::SavePageFormat savePageFormat () const
void setDownloadDirectory (const QString & directory )
void setDownloadFileName (const QString & fileName )
void setSavePageFormat (QWebEngineDownloadRequest::SavePageFormat format )
QWebEngineDownloadRequest::DownloadState state () const
QString suggestedFileName () const
qint64 totalBytes () const
QUrl url () const

公共槽

void accept ()
void cancel ()
void pause ()
void resume ()

信號

void downloadDirectoryChanged ()
void downloadFileNameChanged ()
void interruptReasonChanged ()
void isFinishedChanged ()
void isPausedChanged ()
void receivedBytesChanged ()
void savePageFormatChanged ()
void stateChanged (QWebEngineDownloadRequest::DownloadState state )
void totalBytesChanged ()

詳細描述

QWebEngineDownloadRequest 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 QWebEngineDownloadRequest. The application can then examine this item and decide whether to accept it or not. When a decision is made, the application must explicitly call accept () 或 cancel () on the item for Qt WebEngine to actually start downloading or rejecting the request.

注意: 某些特性,如設置文件保存路徑和文件名 (見 downloadDirectory () 和 downloadFileName ()),纔可以改變先於調用 accept ().

對象生命周期

In each and every case, the QWebEngineProfile takes the ownership of the item. However, it is safe for the application to delete the item at any time, except during the handling of the downloadRequested 信號。 QWebEngineProfile 是長期存活對象,事實上,推薦應用程序刪除它不再感興趣的任何項。

注意: 從 5.12.2 起刪除項也會被自動取消下載,但為瞭可移植性,推薦在刪除之前手動取消。

網頁下載

除正常文件下載 (簡單地從網絡檢索一些原生字節並把它們寫入磁盤) 外,Qt WebEngine 還支持保存完整網頁,涉及剖析頁麵的 HTML、下載任何從屬資源及把潛在的一切打包進特殊文件格式 ( savePageFormat )。要檢查下載的是文件還是網頁,使用 isSavePageDownload .

Web page save requests are accepted automatically and started from DownloadInProgress state by convenience reasons. The first directly connected downloadRequested signal handler can prevent this by calling cancel (), otherwise the save operation will start writing data to the disk.

另請參閱 QWebEngineProfile , QWebEngineProfile::downloadRequested , QWebEnginePage::download ,和 QWebEnginePage::save .

成員類型文檔編製

enum QWebEngineDownloadRequest:: DownloadInterruptReason

描述下載為什麼被中斷的原因:

常量 描述
QWebEngineDownloadRequest::NoReason 0 未知原因或未中斷。
QWebEngineDownloadRequest::FileFailed 1 常規文件操作故障。
QWebEngineDownloadRequest::FileAccessDenied 2 文件無法在本地寫入,由於訪問限定。
QWebEngineDownloadRequest::FileNoSpace 3 目標驅動器空間不足。
QWebEngineDownloadRequest::FileNameTooLong 5 目錄或文件名太長。
QWebEngineDownloadRequest::FileTooLarge 6 文件大小超過文件係統限製。
QWebEngineDownloadRequest::FileVirusInfected 7 文件被病毒感染。
QWebEngineDownloadRequest::FileTransientError 10 臨時問題 (例如:文件在使用中、內存不足或一次打開太多文件)。
QWebEngineDownloadRequest::FileBlocked 11 文件被阻塞由於本地策略。
QWebEngineDownloadRequest::FileSecurityCheckFailed 12 試圖檢查下載失敗的安全性,由於意外原因。
QWebEngineDownloadRequest::FileTooShort 13 嘗試尋址超齣文件末尾,當打開文件時 (作為再繼續先前被中斷下載的一部分)。
QWebEngineDownloadRequest::FileHashMismatch 14 部分文件不匹配預期哈希。
QWebEngineDownloadRequest::NetworkFailed 20 常規網絡故障。
QWebEngineDownloadRequest::NetworkTimeout 21 網絡操作已超時。
QWebEngineDownloadRequest::NetworkDisconnected 22 網絡連接已被終止。
QWebEngineDownloadRequest::NetworkServerDown 23 服務器宕機。
QWebEngineDownloadRequest::NetworkInvalidRequest 24 網絡請求無效 (例如:原始或重定嚮 URL 無效,方案不受支持或被策略禁止)。
QWebEngineDownloadRequest::ServerFailed 30 常規服務器故障。
QWebEngineDownloadRequest::ServerBadContent 33 服務器沒有請求的數據。
QWebEngineDownloadRequest::ServerUnauthorized 34 服務器未授權訪問資源。
QWebEngineDownloadRequest::ServerCertProblem 35 服務器證書發生問題。
QWebEngineDownloadRequest::ServerForbidden 36 訪問被服務器禁止。
QWebEngineDownloadRequest::ServerUnreachable 37 意外服務器響應 (可能指示響應服務器,可能不是企圖服務器)。
QWebEngineDownloadRequest::UserCanceled 40 用戶取消下載。

enum QWebEngineDownloadRequest:: DownloadState

此枚舉描述下載的狀態:

常量 描述
QWebEngineDownloadRequest::DownloadRequested 0 下載已請求,但尚未接受。
QWebEngineDownloadRequest::DownloadInProgress 1 下載正在進行中。
QWebEngineDownloadRequest::DownloadCompleted 2 下載成功完成。
QWebEngineDownloadRequest::DownloadCancelled 3 下載已被取消。
QWebEngineDownloadRequest::DownloadInterrupted 4 下載已被中斷 (由服務器或由於丟失連接)。

enum QWebEngineDownloadRequest:: SavePageFormat

此枚舉描述用於保存網頁的格式。

常量 描述
QWebEngineDownloadRequest::UnknownSaveFormat -1 這不是下載完整網頁的請求。
QWebEngineDownloadRequest::SingleHtmlSaveFormat 0 頁麵被另存為單 HTML 頁麵。圖像等資源不被保存。
QWebEngineDownloadRequest::CompleteHtmlSaveFormat 1 頁麵被另存為完整 HTML 頁麵,例如:目錄包含單 HTML 頁麵和資源。
QWebEngineDownloadRequest::MimeHtmlSaveFormat 2 以 MIME HTML 格式,把頁麵另存為完整網頁。

特性文檔編製

[read-only] isFinished : const bool

This property holds whether this download is finished (completed, cancelled, or non-resumable interrupted state).

訪問函數:

bool isFinished () const

通知程序信號:

void isFinishedChanged ()

另請參閱 state ().

[read-only] isPaused : const bool

此特性保持該下載是否暫停。

訪問函數:

bool isPaused () const

通知程序信號:

void isPausedChanged ()

另請參閱 pause () 和 resume ().

成員函數文檔編製

[slot] void QWebEngineDownloadRequest:: accept ()

接受當前下載請求,將開始下載。

若項在 DownloadRequested 狀態,那麼它將過渡到 DownloadInProgress 狀態,且下載會開始。若項在任何其它狀態,則什麼都不會發生。

另請參閱 isFinished and stateChanged ().

[slot] void QWebEngineDownloadRequest:: cancel ()

取消當前下載。

若項在 DownloadInProgress 狀態,那麼它將過渡到 DownloadCancelled 狀態,下載會停止,且部分下載文件會從磁盤被刪除。

若項在 DownloadCompleted 狀態,則什麼都不會發生。若項在任何其它狀態,則它會過渡到 DownloadCancelled 狀態,沒有進一步影響。

另請參閱 isFinished and stateChanged ().

QString QWebEngineDownloadRequest:: downloadDirectory () const

返迴下載目錄路徑。

注意: Getter function for property downloadDirectory.

另請參閱 setDownloadDirectory ().

QString QWebEngineDownloadRequest:: downloadFileName () const

返迴要下載文件的文件名。

注意: getter 函數對於特性 downloadFileName。

另請參閱 setDownloadFileName ().

quint32 QWebEngineDownloadRequest:: id () const

返迴下載項 ID。

注意: getter 函數對於特性 id。

QWebEngineDownloadRequest::DownloadInterruptReason QWebEngineDownloadRequest:: interruptReason () const

返迴下載為什麼被中斷的原因。

注意: getter 函數對於特性 interruptReason。

另請參閱 interruptReasonString ().

QString QWebEngineDownloadRequest:: interruptReasonString () const

返迴人類可讀的中斷下載原因的描述。

注意: getter 函數對於特性 interruptReasonString。

另請參閱 interruptReason ().

[signal] void QWebEngineDownloadRequest:: isPausedChanged ()

此信號發射,每當 isPaused 改變。

注意: 通知程序信號對於特性 isPaused .

另請參閱 pause () 和 isPaused .

bool QWebEngineDownloadRequest:: isSavePageDownload () const

返迴 true 若這是用於保存網頁的下載請求。

注意: Getter function for property isSavePageDownload.

另請參閱 savePageFormat () 和 setSavePageFormat ().

QString QWebEngineDownloadRequest:: mimeType () const

返迴下載的 MIME 類型。

注意: Getter function for property mimeType.

QWebEnginePage *QWebEngineDownloadRequest:: page () const

返迴請求下載的頁麵。若下載不由頁麵內容所觸發, nullptr 被返迴。

[slot] void QWebEngineDownloadRequest:: pause ()

暫停下載。

不起作用,若狀態不是 DownloadInProgress 。不改變狀態。

另請參閱 resume () 和 isPaused ().

qint64 QWebEngineDownloadRequest:: receivedBytes () const

返迴到目前為止已下載的數據數量 (以字節為單位)。

-1 意味著尺寸未知。

注意: Getter function for property receivedBytes.

[slot] void QWebEngineDownloadRequest:: resume ()

再繼續當前下載,若它被暫停或中斷。

不起作用,若狀態不是 DownloadInProgress or DownloadInterrupted 。不改變狀態。

另請參閱 pause (), isPaused (),和 state ().

QWebEngineDownloadRequest::SavePageFormat QWebEngineDownloadRequest:: savePageFormat () const

返迴保存網頁的格式,若這是針對網頁的下載請求。

注意: Getter function for property savePageFormat.

另請參閱 setSavePageFormat () 和 isSavePageDownload ().

void QWebEngineDownloadRequest:: setDownloadDirectory (const QString & directory )

設置 directory 作為要下載文件的目錄路徑。

下載目錄纔可以被設置為響應 QWebEngineProfile::downloadRequested () 信號在接受下載前。此後,此函數對下載項狀態不起作用。

注意: setter 函數對於特性 downloadDirectory .

另請參閱 downloadDirectory ().

void QWebEngineDownloadRequest:: setDownloadFileName (const QString & fileName )

設置 fileName 作為要下載文件的文件名。

下載文件名纔可以被設置為響應 QWebEngineProfile::downloadRequested () 信號在接受下載前。此後,此函數對下載項狀態不起作用。

注意: setter 函數對於特性 downloadFileName .

另請參閱 downloadFileName ().

void QWebEngineDownloadRequest:: setSavePageFormat ( QWebEngineDownloadRequest::SavePageFormat format )

設置 format 為網頁保存,若這是網頁下載請求。

注意: setter 函數對於特性 savePageFormat .

另請參閱 savePageFormat () 和 isSavePageDownload ().

QWebEngineDownloadRequest::DownloadState QWebEngineDownloadRequest:: state () const

返迴下載項的當前狀態。

注意: getter 函數對於特性 state。

另請參閱 DownloadState .

[signal] void QWebEngineDownloadRequest:: stateChanged ( QWebEngineDownloadRequest::DownloadState state )

此信號發射每當下載的 state 改變。

注意: 通知程序信號對於特性 state .

另請參閱 state () 和 DownloadState .

QString QWebEngineDownloadRequest:: suggestedFileName () const

返迴建議的文件名。

注意: getter 函數對於特性 suggestedFileName。

qint64 QWebEngineDownloadRequest:: totalBytes () const

返迴要下載的數據總量 (以字節為單位)。

-1 意味著尺寸未知。

注意: getter 函數對於特性 totalBytes。

QUrl QWebEngineDownloadRequest:: url () const

返迴下載的原始 URL。

注意: getter 函數對於特性 url。