问题描述
我使用 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
的详细描述.
但是,可以将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
读取.换句话说,对于QNetworkReply
的IODevice
基类,我们需要 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.
如何编写此代理?
推荐答案
似乎有人已经想要相同的东西并写了 QNetworkReply的代理.
It looks like someone has already wanted the same and wrote a proxy for the QNetworkReply.
这篇关于如何从QWebPage正在使用的QNetworkReply中读取数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!