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 is a sequential-access
QIODevice, which means that once data
is read from the object, it no longer
kept by the device.
according to detailed description of QNetworkReply
.
However QWebPage
can be configured to use custom QNetworkAccessManager
with overriden createRequest
method
QNetworkReply * QNetworkAccessManager::createRequest ( Operation op, const QNetworkRequest & req, QIODevice * outgoingData = 0 )
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.
How to write this proxy?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…