Hello all im beginner with QtWebKit i build simple web frame that loaded page ( server side ) and when from this page i submit data i like to catch the response string from the server in the c++ side how can i do that ?
You can use QNetworkReply
class for it. QWebPage
instances have networkAccessManager()
method that returns a QNetworkAccessManager
instance capable of sending requests and receiving responses.
You need to look for its finished
signal.
void QNetworkAccessManager::finished ( QNetworkReply * reply )
This signal is emitted whenever a pending network reply is finished. The reply parameter will contain a pointer to the reply that has just finished.
QNetworkReply
in its turn is an inheritor of QIODevice
therefore you are able to call its readAll()
method in order to receive the response data.
You may also find this question useful.
I tinkered around with Qt (which I'm new to) and found a way to catch all resources downloaded by WebKit. Here's how:
1) Create your own subclass of QNetworkAccessManager
2) In your derived class, override virtual function createRequest
3) Call base class implementation to get the response object. After that you can look at the URL (or other parameters) and determine whether you need to capture that particular resource or not
4) if you do - connect readyRead signal to some slot that will capture the data
5) in that slot call peek function to read data so that WebKit will get the data also
6) After creating QWebPage object, call setNetworkAccessManager and pass a newly created instance of your subclass from step 1)
That's it - enjoy!