How to read data from QNetworkReply being used by QWebPage?

随声附和 提交于 2019-12-28 13:56:09

问题


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?


回答1:


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



来源:https://stackoverflow.com/questions/4475647/how-to-read-data-from-qnetworkreply-being-used-by-qwebpage

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!