I'm trying different ways but with no luck.

First of all the code:
Qt Code:
  1. class InternetJob: public QObject
  2. {
  3. Q_OBJECT
  4.  
  5. public:
  6. InternetJob(const QString &u);
  7. QByteArray getData(){return data;}
  8. int getStatusCode(){return statusCode;}
  9. QString getLocation(){return location;}
  10. bool isRequestAborted(){return httpRequestAborted;}
  11. bool isRedirecting(){return needRedirect;}
  12. void download();
  13.  
  14. private slots:
  15. void httpRequestFinished(int requestId, bool error);
  16. void readResponseHeader(const QHttpResponseHeader &responseHeader);
  17.  
  18. signals:
  19. void requestFinished();
  20.  
  21. private:
  22. QHttp *http;
  23. QUrl url;
  24. bool httpRequestAborted;
  25. int httpGetId;
  26. QByteArray data;
  27. int statusCode;
  28. QString location;
  29. };
  30.  
  31. InternetJob::InternetJob(const QString &u)
  32. : url(u)
  33. {
  34. http = new QHttp;
  35. connect(http, SIGNAL(responseHeaderReceived(const QHttpResponseHeader &)), this, SLOT(readResponseHeader(const QHttpResponseHeader &)));
  36. connect(http, SIGNAL(requestFinished(int, bool)), this, SLOT(httpRequestFinished(int, bool)));
  37.  
  38. download();
  39. }
  40.  
  41. void InternetJob::download()
  42. {
  43. QString query;
  44. for(int i = 0; i < url.queryItems().size(); ) {
  45. query += url.queryItems().at(i).first + "=" + url.queryItems().at(i).second;
  46. if(++i < url.queryItems().size())
  47. query += "&";
  48. }
  49.  
  50. if(url.queryItems().size() > 0)
  51. header.setRequest("GET", url.path() + "?" + QUrl::toPercentEncoding(query,"&="));
  52. else
  53. header.setRequest("GET", url.path());
  54. header.setValue("Host", url.host());
  55.  
  56. httpRequestAborted = false;
  57. http->setHost(url.host());
  58. httpGetId = http->request(header);
  59. qDebug() << "job id = " << httpGetId;
  60. }
  61.  
  62. void InternetJob::readResponseHeader(const QHttpResponseHeader &responseHeader)
  63. {
  64. statusCode = responseHeader.statusCode();
  65. QRegExp rx("\?$");
  66.  
  67. switch(statusCode) {
  68. case 200:
  69. case 301:
  70. case 303:
  71. case 307:
  72. break;
  73.  
  74. case 302:
  75. location = responseHeader.value("Location");
  76. // Remove trailing "?"
  77. location.remove(rx.indexIn(location), 1);
  78. httpRequestAborted = true;
  79. http->abort();
  80. break;
  81.  
  82. default:
  83. qDebug() << QString(trUtf8("Download failed: %1.").arg(responseHeader.reasonPhrase()));
  84. httpRequestAborted = true;
  85. http->abort();
  86. }
  87. }
  88.  
  89. void InternetJob::httpRequestFinished(int requestId, bool error)
  90. {
  91. if (requestId != httpGetId)
  92. return;
  93. qDebug() << "job finished = " << requestId;
  94. if (httpRequestAborted) {
  95. qDebug() << "Request Aborted. Status Code: " << statusCode;
  96. if(statusCode == 302) {
  97. url.setUrl(location);
  98. download();
  99. return;
  100. }
  101. else {
  102. emit requestFinished();
  103. return;
  104. }
  105. }
  106.  
  107. if(error)
  108. qDebug() << QString(trUtf8("Download failed: %1.").arg(http->errorString()));
  109. else
  110. data = http->readAll();
  111. emit requestFinished();
  112. }
To copy to clipboard, switch view to plain text mode 

The code above works well until the http status code is 200; if the status code is 302 it starts a new http->request(...) but after it neither responseHeaderReceived nor httpRequestFinished signals are emitted.

Where is my mistake?

Thanks