开发者

How to read data from QNetworkReply being used by QWebPage?

开发者 https://www.devze.com 2023-01-31 08:43 出处:网络
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 QNetwo

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?


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号