PDA

View Full Version : XP/Qt 4.1.4 qhttp



incapacitant
30th June 2006, 17:28
I have the following code that usually works fine :


//************************************************** ***************************
void ApplicationWindow::creditUrl()
//************************************************** ***************************
{
// target url
QUrl url("http://api.smsbox.fr/index.php?");
url.addQueryItem("login", iniGet( "Login" ));
url.addQueryItem("pass", iniGet( "Password" ));
url.addQueryItem("action", iniGet( "Action" ));

http = new QHttp(this);
connect(http, SIGNAL(done(bool)), this, SLOT(defineSMSCredit(bool)));

// remember to set the host
http->setHost(url.host());

// the resulting data will be stored in the buffer
buffer = new QBuffer(this);
http->get(url.toString(), buffer);

}


But right now I am on a friend's network that is loaded with BitTorrents.
And now here the program just goes away, leaving a useless TrayIcon icon that also goes away as soon as you hover on it.

Is there a sort of time out somewhere ?
I would have thought the connect would wait, whatever time it takes...
Firefox or IE do wait.

Any hint ?

incapacitant
30th June 2006, 19:01
I edited the code a bit (i was showing the wrong proc, but it is the same code, just a ditfferent outbound slot) to trace it a bit :


//************************************************** ***************************
void ApplicationWindow::creditUrl()
//************************************************** ***************************
{
// target url
QMessageBox::warning( this, "creditUrl", "start" );
QUrl url("http://api.smsbox.fr/index.php?");
url.addQueryItem("login", iniGet( "Login" ));
url.addQueryItem("pass", iniGet( "Password" ));
url.addQueryItem("action", iniGet( "Action" ));

http = new QHttp(this);
QMessageBox::warning( this, "creditUrl", "connect" );
connect(http, SIGNAL(done(bool)), this, SLOT(defineSMSCredit(bool)));

// remember to set the host
http->setHost(url.host());

// the resulting data will be stored in the buffer
buffer = new QBuffer(this);
QMessageBox::warning( this, "creditUrl", "get" );
http->get(url.toString(), buffer);

}




The the slot proc :


//************************************************** ***************************
void ApplicationWindow::defineSMSCredit( bool error )
//************************************************** ***************************
{
QMessageBox::warning( this, "defineSMSCredit", "before handle" );
// handle http reply for credit request
handleSMSCredit( error );
QMessageBox::warning( this, "defineSMSCredit", "after handle" );
etc...


When I run that I see:
start
connect
before handle
and then it goes away...

jacek
30th June 2006, 19:05
When I run that I see:
start
connect
before handle
and then it goes away...
Well... it works until handleSMSCredit() is invoked. What does it do?

incapacitant
30th June 2006, 21:01
Yes, it does this :


//************************************************** ***************************
void ApplicationWindow::handleSMSCredit( bool error )
//************************************************** ***************************
{
// by default there is no credit, but qsLCredit and intCredit should be
// defini. This is in the case where the credit cannot be retrieved
// after a http problem (like no connection to server)
// "Bidon 0" ensures intCredit is defaulted to 0, and qslCredit|1] = "0"
QMessageBox::warning( this, "handleSMSCredit", "start" );
qsCredit = "Bidon 0";
qslCredit = qsCredit.split( " " );
intCredit = qslCredit[1].toInt( &ok, 10 );

// si pas d'erreur http
if ( !error ) {
QMessageBox::warning( this, "handleSMSCredit", "no error" );
// get credit info returned by http slot
qsCredit = QString(buffer->data());
QMessageBox::warning( this, "handleSMSCredit", qsCredit );

// parse buffer
qslCredit = qsCredit.split( " " );
QMessageBox::warning( this, "handleSMSCredit", "parse buffer data" );

// check what server replied (ie "ERROR xx" or "CREDIT xxx")
TxtError = iniGet( "TxtError1" );

QMessageBox::warning( this, "handleSMSCredit", qslCredit[0] );


When I run I see:
Credit...
start
connect
DefineSMS...
before handle
handleSMLSCredit
start
no error
a "get" appears and disapears in less than half a second
shows the value of qsCredit as empty
parse buffer data
a new "get" appears and disapears in less than half a second
show the value of qslCredit[0] as empty (as qsCredit)

So I paused the torrents to see. But somehow this application used to work.
And with the torrents paused it won't : qsCredit is returned empty !

It is a programming issue, because the previous version works despite the torrents.
I must have done something while trying to improve things and now I will investigate
what I did between the 2 versions.
Qt works, my new code does not.

Thanks