PDA

View Full Version : problem with Synchronous Http request



rchaitanya
29th January 2009, 09:20
HI,

I am using Qt-extended4.43.
i am trying to make synchronous http connection.but its not connecting.

Can any one help me?
Here is the sample code.


bool syncPostURL( const QUrl& url, const QByteArray& data) {
///connect the requestFinished signal to our finished slot
connect(this,SIGNAL(requestFinished(int,bool)),SLO T(finished (int,bool)));
QHttpRequestHeader header("POST", url.path());
header.setContentType("application/x-www-form-urlencoded");
header.setValue("Host", url.host());

/// start the request and store the requestID
requestID = request(header,data);

/// block until the request is finished
loop.exec();
/// return the request status
return status;
}

virtual void finished ( int idx, bool err )
{
/// check to see if it's the request we made
if ( idx!=requestID )
return;
/// set status of the request
status = !err;
/// end the loop
loop.exit();
}

wysota
30th January 2009, 00:42
The loop will exit on the first request being finished and the first request is a call to setHost(). Connect to done() instead.

rchaitanya
30th January 2009, 11:03
Thanx for the reply.............Now, My next question is

Above code is working in QtEmbedded as well as Qt -X11.
But it is not connecting in QT Extended.

The only difference is in writing the main() function.

In Qt Extended the main() function is

QTOPIA_ADD_APPLICATION(QTOPIA_TARGET, MYCLASS)
QTOPIA_MAIN

In Qt X11 and Qt-Embeded the main function is

int main(int argc , char * argv[])
{ QApplication app (argc, argv);
MYCLASS obj;
return app.exec()
}