I am trying to intercept a page / form request in Qt QWebView and in some cases respond with alternative content.
QNetworkReply* ngcBrowser::createRequest(Operation operation, const QNetworkRequest& request, QIODevice* ioDevice) { view->page()->setNetworkAccessManager(this); QNetworkReply* response = NULL; if (request.url().path().endsWith("ajax")) { response = QNetworkAccessManager::createRequest(operation, request, ioDevice); response->write("{ success: true }"); } else { response = QNetworkAccessManager::createRequest(operation, request, ioDevice); } return response; }
As you can see above, I overridden the QNAM createRequest method to receive all page requests and response using a JSON object if Url ends with the .ajax extension. However, it is difficult for me to write the data back to the network stream.
Any hints or tips on how to do this?
Cheers, Ben
Update:
Hi Abhijit, I tried to solve the problem, but could not connect the signal to the slot.
QNetworkAccessManager* nam = view->page()->networkAccessManager(); bool status = QObject::connect(nam, SIGNAL(finished(QNetworkReply*)), this, SLOT(replyReceived(QNetworkReply*))); if(!status) { QErrorMessage errorMessage; errorMessage.showMessage("connect failed"); errorMessage.exec(); }
Error:
Object :: connect: there is no such slot ngcBrowser :: replyRecieved (QNetworkReply *)
Update
Well, I managed to get it working, however, when I try to write to IODevice, this does not indicate its ReadOnly device.
Thanks for the help.
source share