【发布时间】:2015-05-26 14:07:19
【问题描述】:
我们目前正在将一个项目从QtWebkit 迁移到QWebEngine。但是,处理下载会让人有些头疼。之前我们使用QWebPage::unsupportedContent 信号处理这个问题,如下所示:
QWebPage* webPage = new QWebPage(this);
QObject::connect(webPage, &QWebPage::unsupportedContent, [] (QNetworkReply* reply) {
// do stuff with the reply
reply->readAll();
});
当使用QtWebEngine 时,我唯一能想到的就是使用QWebEngineView::urlChanged 信号向服务器发出请求,我什至不确定这是否可行。
QNetworkAccessManager* accessManager = new QNetworkAccessManager(this);
QWebEngineView* webView = new QWebEngineView(this);
QObject::connect(webView, &QWebEngineView::urlChanged, [=] (const QUrl& url) {
if (url.path().endsWith("some_endpoint_which_results_in_a_download") {
QNetworkReply* reply = accessManager->get(url);
// do the same stuff to the reply
reply->readAll();
}
})
显然,这种方法非常有限,因为导致下载的端点必须硬编码到应用程序中。但是,我看不到更好的解决方案。有没有人想出更好的办法?
-- 更新--
来自 Qt 的 5.5 Release plan 的文档概述了开发人员对 Web 缓存和 cookie 的控制的其他改进,以及以下功能。
添加了用于管理文件下载的 API
5.5 测试版将于 2015 年 9 月 4 日发布,最终版将于 2015 年 5 月 26 日发布。
为了防止进一步的头部外伤,等待这些改进可能是值得的。
话虽如此,如果有人有的话,我仍然对比我更清洁的解决方案感兴趣。
【问题讨论】:
-
我们不得不做出类似的决定,并选择继续使用 webkit,直到 Blink 集成更加完整。还缺少通过 QNetworkManager 进行的请求修改并且还没有打印。有关如何使用 Qt 5.5 解决此问题的示例,请查看 otter browser 和 Qt sources。
-
@StickyCube 你能告诉我你是如何启动网络引擎的吗?我正在尝试将 quicknanobrowser 用作 ./quicknanobrowser -platform wayland。但是,在播放 youtube 视频时,该应用程序崩溃了。如果您有任何建议,请给我留言。
标签: c++ qt qt5.4 qtwebengine