Hi Guys,

With the following Qt Code I am trying to send an QHttp request and get the related
response, doing this turning the asynchronous operation into a synchronous one,
without using signals and slots..

Here the code:
Qt Code:
  1. http = new QHttp(this);
  2. ....
  3. int id = http->request(header, byteArray);
  4.  
  5. while(http->currentId() != 0)
  6. {
  7. qApp->processEvents();
  8. }
  9.  
  10. QString result = http->readAll();
To copy to clipboard, switch view to plain text mode 

In my PC I get the result correctly, in other ones the Gui seems to freeze and the application don't get on..

I am wandering if the "qApp->processEvents();" instruction is the problem and how i can avoid this behaviour..

Using
Qt Code:
  1. while(http->currentId() != 0)
  2. {
  3. QCoreApplication::processEvents();
  4. }
To copy to clipboard, switch view to plain text mode 

would be the same?

If so, what about the fallowing method ??
Qt Code:
  1. QNetworkAccessManager manager;
  2. QTimer tT;
  3.  
  4. tT.setSingleShot(true);
  5. connect(&tT, SIGNAL(timeout()), &q, SLOT(quit()));
  6. connect(&manager, SIGNAL(finished(QNetworkReply*)),
  7. &q, SLOT(quit()));
  8. QNetworkReply *reply = manager.get(QNetworkRequest(
  9. QUrl("http://www.qtcentre.org")));
  10.  
  11. tT.start(5000); // 5s timeout
  12. q.exec();
  13.  
  14. if(tT.isActive()){
  15. // download complete
  16. tT.stop();
  17. } else {
  18. // timeout
  19. }
To copy to clipboard, switch view to plain text mode 

How to adapt it to perform my task (sending request and waiting for its response before going on with the flow) ???


Many thanks in advance

Roby