Hi,

I coded to download a RSS file :

The problem is that the QByteArray seems to be truncated because of the code of the connect finished() -> deleteLater()
If I don't connect, qdebug() seems to have a weird behavior, I'm not sure what to do.

At term, I would like to be able to read the entire QByteArray (content of RSS) to fill a local file with some of the content, and it will be a thread loop, to netReply, and others, will be reused.

Here is my code :
Qt Code:
  1. void Window::requestRSSalaune(){
  2. QString urlRss = "http://rss.lemonde.fr/c/205/f/3050/index.rss";
  3.  
  4. netRequest = QNetworkRequest(QUrl(urlRss));
  5. netReply = netMan->get(netRequest);
  6.  
  7. QObject::connect (netReply, SIGNAL(readyRead()), this, SLOT(downloadedRSSalaune())) ;
  8.  
  9. //QObject::connect (netReply, SIGNAL(finished()), netReply, SLOT(deleteLater())) ;
  10. }
  11.  
  12. void Window::downloadedRSSalaune(){
  13.  
  14. qDebug() << netReply->errorString();
  15.  
  16. if(netReply->error() != QNetworkReply::NoError)
  17. return;
  18.  
  19. QByteArray data =QByteArray(netReply->readAll());
  20.  
  21.  
  22. int statusCode = netReply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
  23. qDebug() << QVariant(statusCode).toString();
  24.  
  25. if(data.isEmpty())
  26. return;
  27.  
  28. qDebug()<<data;
  29. }
To copy to clipboard, switch view to plain text mode 

First, connect finished is commented, here is the result :

Qt Code:
  1. "Unknown error"
  2. "200"
  3. "<?xml><rss><channel>[..]and lot of other words but during the sen"
  4. "Unknown error"
  5. "200"
  6. "tence, qDebug() printed others things, as if the function was called another time during the print of data</guid></item></channel></rss>"
To copy to clipboard, switch view to plain text mode 

Secondly, if I uncomment the connection finished() | deleteLater() :
Qt Code:
  1. "Unknown error"
  2. "200"
  3. "<?xml version='1.0' encoding='UTF-8'?>[...] and other words until this mome"
  4. "Unknown error"
  5. "200"
To copy to clipboard, switch view to plain text mode 

So in this second case, the printing of data is not finished so seemed to be cut.
In the second case, when I uncomment, I have some execution where the qDebug() print is similar as when it's commented, it's very not regular.


So I don't really know how to manage it
Thanks in advance for your contribution.