开发者

how to get response in QtWebKit

im beginner with QtWebK开发者_StackOverflow社区it 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 ?


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!


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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜