Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to read data from QNetworkReply being used by 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 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?

like image 667
Piotr Dobrogost Avatar asked Oct 14 '22 19:10

Piotr Dobrogost


1 Answers

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

like image 117
Piotr Dobrogost Avatar answered Nov 15 '22 09:11

Piotr Dobrogost