QWebEngineView QWebEngineDownloadItem 下载网页资源

一、效果图
QWebEngineView QWebEngineDownloadItem 下载网页资源_第1张图片
二、代码

void WebDownloadWork::on_WebDownload(QWebEngineDownloadItem *item)
{
    connect(item,&QWebEngineDownloadItem::finished,this,&WebDownloadWork::on_finished);
    connect(item,&QWebEngineDownloadItem::downloadProgress,this,&WebDownloadWork::on_downloadProgress);
    item->accept();
}

void WebDownloadWork::on_finished()
{
    qDebug()<<"WebDownloadWork::on_finished";
}
void WebDownloadWork::on_downloadProgress(qint64 bytesReceived, qint64 bytesTotal)
{
    qDebug()<<"WebDownloadWork::on_downloadProgress bytesReceived:"<

三、总结
1.网页下载会触发QWebEngineView->QWebEnginePage->QWebEngineProfile 中的 void downloadRequested(QWebEngineDownloadItem *download);
2.QWebEngineDownloadItem管理每次触发的下载请求,可以设置文件下载路径和下载名称

你可能感兴趣的:(【Qt】)