[Qt-interest] Fwd: QHttp howto get response code ? e.g 200 , 404
Aaron Lewis
aaron.lewis1989 at gmail.com
Sun Mar 14 13:37:45 CET 2010
Hi Rohan,
It doesn't seems to work ..
Sample Code:
/*
Response Code Handler
*/
void webscanner::signalHandler(const QHttpResponseHeader &resHeader)
{
int status = resHeader.statusCode();
qDebug() << "Status is " << status;
}
// In construct function of my class, i have
connect(&req,SIGNAL(responseHeaderReceived(const
QHttpResponseHeader&)),this,SLOT(signalHandler(const
QHttpResponseHeader&)));
// in header file of my class , i declared req.
private:
QHttp req;
----------------------
This is the function `checkPage' :
void myweb::checkPage(QString url) // webBox is ComboBox
-snip-
req.setHost(ui->webBox->currentText());
if(method.toLatin1() == "GET")
{
req.get(url);
// updateStatusBar("Request Sent .. [GET]");
}else if(method.toLatin1() == "POST"){
req.post(url,"");
// updateStatusBar("Request Sent .. [POST]");
}
-------------------------
In Main Function:
checkPage(siteUrl);
I opened my apache server , do local test , put siteUrl like
"http://127.0.0.1/~aaron/index.html" (firefox can access it) ,
With QtCreator , it prints nothing in `Application Output' , was there
anything wrong with Signal or my Slot ?
Rohan Prabhu wrote:
>
>
> Hi Rohan,
>
> Should i write this:
> -snip-
> QHttp req;
> connect(req,SIGNAL(responseHeaderReceived(const
> QHttpResponseHeader&)),this,SLOT(signalHandler(const
> QHttpResponseHeader&)));
> -snip-
>
>
> Yes. That is exactly what you need to do as
> responseHeaderReceived(const QHttpResponse&) is a signal of the QHttp
> class.
>
>
> But i think `req' is not a QObject , so i can't write this .. I'm
> really not very familar with QHttp ..
>
>
> 'req' in your case is an instance of the class QHttp, which is derived
> from QObject.
>
> regards,
> rohan
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
>
--
Best Regards,
Aaron Lewis - PGP: 0x4A6D32A0
FingerPrint EA63 26B2 6C52 72EA A4A5 EB6B BDFE 35B0 4A6D 32A0
irc: A4r0n on freenode
More information about the Qt-interest-old
mailing list