如何从QWebPage正在使用的QNetworkReply中读取数据? [英] How to read data from QNetworkReply being used by QWebPage?

查看:338
本文介绍了如何从QWebPage正在使用的QNetworkReply中读取数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 QWebPage 下载网页及其所有网页资源.同时,我想掌握Qt在此过程中下载的原始数据.为此,请从 QNetworkReply 中读取数据://doc.qt.nokia.com/latest/qnetworkaccessmanager.html#finished"rel =" nofollow> void QNetworkAccessManager::finished(QNetworkReply * reply) 信号不是一个好的解决方案,因为QWebPage本身可能已经读取了数据.这是因为

I use QWebPage to download a webpage as well as all its resources. At the same time I'd like to get hold on raw data being downloaded by Qt during this process. Doing this by reading data from QNetworkReply in void QNetworkAccessManager::finished(QNetworkReply * reply) signal is not a good solution as data could have been already read by QWebPage itself. This is because

QNetworkReply是顺序访问 QIODevice,这意味着一次数据 从对象读取,它不再 由设备保存.

QNetworkReply is a sequential-access QIODevice, which means that once data is read from the object, it no longer kept by the device.

根据QNetworkReply详细描述.

但是,可以将QWebPage配置为使用自定义 QNetworkAccessManager 覆盖createRequest方法

However QWebPage can be configured to use custom QNetworkAccessManager with overriden createRequest method

QNetworkReply * QNetworkAccessManager::createRequest ( Operation op, const QNetworkRequest & req, QIODevice * outgoingData = 0 )

我认为正确的解决方案是为QNetworkReply创建代理,然后在createRequest方法中将其返回.该代理应该允许从答复中读取数据,就像原始的QNetworkReply一样(以便QWebPage可以从中读取数据),但是与此同时,该代理还应该允许其他对象读取数据后再从中读取数据.由QWebPage读取.换句话说,对于QNetworkReplyIODevice基类,我们需要 tee

I think the right solution would be to create a proxy for QNetworkReply and return it in the createRequest method. This proxy should allow for reading data from reply as is the case with the original QNetworkReply (so that QWebPage could read data from it) but at the same time this proxy should allow for reading data by other objects after it have been read by QWebPage. In other words we need tee for QNetworkReply's IODevice base class.

如何编写此代理?

推荐答案

似乎有人已经想要相同的东西并写了

It looks like someone has already wanted the same and wrote a proxy for the QNetworkReply.

这篇关于如何从QWebPage正在使用的QNetworkReply中读取数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆