QtWebkit: How to check HTTP status code? -


i'm writing thumbnail generator per an example in qtwebkit documentation. avoid screenshots of error pages such 404 not found or 503 internal server error.

however, qwebpage::loadfinished() signal emitted ok = true when page gives http error. there way in qtwebkit check http status code on response?

turns out need monitor qnetworkaccessmanager associated qwebpage , wait finished(...) signal. can inspect http response , check status code asking qnetworkrequest::httpstatuscodeattribute attribute.

it's better explained in code:

void myclass::initwebpage() {   myqwebpage = new qwebpage(this);   connect(     myqwebpage->networkaccessmanager(), signal(finished(qnetworkreply *)),     this, slot(httpresponsefinished(qnetworkreply *))   ); }  void myclass::httpresponsefinished(qnetworkreply * reply) {   switch (reply->error())   {     case qnetworkreply::noerror:       // no error       return;     case qnetworkreply::contentnotfounderror:       // 404 not found       failedurl = reply->request.url();       httpstatus = reply->attribute(         qnetworkrequest::httpstatuscodeattribute).toint();       httpstatusmessage = reply->attribute(         qnetworkrequest::httpreasonphraseattribute).tobytearray();       break;     } } 

there more networkerrors choose from, e.g. tcp errors or http 401.


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -