Re: qApp->processEvents();
Use the second method, it's beautiful ;)
Your code from the first one is incorrect, anyway. You might employ a local event loop to make it work, but it's a bad idea.
How to use the code? Well... after the exec() call you will either have your reply in the reply object ready to read or a timeout will have occured. The "if" block is there to check which one occured. Then simply do your stuff.
Re: qApp->processEvents();
many thanks Wysota..
Just to better understand, you mean that the code that follows
Code:
while(http->currentId() != 0)
{
}
is also incorrect ??
Then, about the second method, I would like you to suggest how to modify the first part of code. I well understand the "if block".
Is it correct like this ?
Code:
tT.setSingleShot(true);
connect(&tT, SIGNAL(timeout()), &q, SLOT(quit()));
connect(http, SIGNAL(finished(QNetworkReply*)),&q, SLOT(quit()));
//**********************
id = http->request(header, b);
//**********************
tT.start(5000); // 5s timeout
q.exec();
if(tT.isActive()){
//*****************
result = http->readAll();
//*****************
tT.stop();
} else {
// timeout
}
Many thanks in advance
Roby
Re: qApp->processEvents();
When I use the code:
Code:
tT.setSingleShot(true);
connect(&tT, SIGNAL(timeout()), &q, SLOT(quit()));
connect(http,
SIGNAL(done
(QHttp*)),
&q,
SLOT(quit
()));
//**********************
id = http->request(header, b);
//**********************
tT.start(5000); // 5s timeout
q.exec();
if(tT.isActive()){
//*****************
result = http->readAll();
//*****************
tT.stop();
} else {
// timeout
}
I can't get to the "if" block, then result is always empty..
What wrongs ??
Roby
Re: qApp->processEvents();
OK Wysota
I made a mistake with the SLOT signal, which is done(bool) in case of http->request..
SO, the code:
Code:
tT.setSingleShot(true);
connect(&tT, SIGNAL(timeout()), &q, SLOT(quit()));
connect(http, SIGNAL(done(bool)),&q, SLOT(quit()));
//**********************
id = http->request(header, b);
//**********************
tT.start(600000); // 6minuto timeout
q.exec();
if(tT.isActive()){
//*****************
result = http->readAll();
//*****************
tT.stop();
} else {
// timeout
}
Seem to be ok..
What's your opinin?
Many thanks in advance..
Roby
Re: qApp->processEvents();
Quote:
Originally Posted by
rmagro
Just to better understand, you mean that the code that follows
Code:
while(http->currentId() != 0)
{
}
is also incorrect ??
No, I mean the loop is incorrect, it would exit too soon.
Quote:
Is it correct like this ?
Code:
tT.setSingleShot(true);
connect(&tT, SIGNAL(timeout()), &q, SLOT(quit()));
Why use QHttp at all if you have a better mechanism available? What's wrong with QNetworkAccessManager?
Re: qApp->processEvents();
Ok ...I can try to adapt my code to use QNetworkAccessManager
but do you thing something is wrong with the code that follows:
Code:
tT.setSingleShot(true);
connect(&tT, SIGNAL(timeout()), &q, SLOT(quit()));
connect(http, SIGNAL(done(bool)),&q, SLOT(quit()));
//**********************
id = http->request(header, b);
//**********************
tT.start(600000); // 6minuto timeout
q.exec();
if(tT.isActive()){
//*****************
result = http->readAll();
//*****************
tT.stop();
} else {
// timeout
}
Thanks
Re: qApp->processEvents();
Any suggestion to adapt the fallowing code to use the QNetworkAccessManager Class ??
Code:
tT.setSingleShot(true);
connect(&tT, SIGNAL(timeout()), &q, SLOT(quit()));
connect(http, SIGNAL(done(bool)),&q, SLOT(quit()));
//**********************
id = http->request(header, b);
//**********************
tT.start(5000); 5s
q.exec();
if(tT.isActive()){
//*****************
result = http->readAll();
//*****************
tT.stop();
} else {
// timeout
}
Re: qApp->processEvents();
Quote:
Originally Posted by
rmagro
Ok ...I can try to adapt my code to use QNetworkAccessManager
but do you thing something is wrong with the code that follows:
Yes, I do. There is no way to properly read the incoming data.
Quote:
Originally Posted by
rmagro
Any suggestion to adapt the fallowing code to use the QNetworkAccessManager Class ??
There is nothing to adapt, just take the original code using QNetworkAccessManager.