Hi,

I'm developping an app on windows which tooltips French news by the system tray.

After succesfully developped the functions that read xml files and fill them, I wanna download the rss file of lemonde.fr (which u know is a xml file) to add the last news in the local xml file.

I tried to do all necessary work for downloading that file but I have a "Unknown error" with reply->errorString(); and then the program crashes.

Here is the principal code :

Qt Code:
  1. Window::Window()
  2. {
  3. AppVars::urlRSSlist << "http://rss.lemonde.fr/c/205/f/3050/index.rss";
  4. AppVars::netManList<< new QNetworkAccessManager(this);
  5. QObject::connect (AppVars::netManList[0], SIGNAL(finished(QNetworkReply*)), this, SLOT(downloadedRSSalaune(QNetworkReply*))) ;
  6. for(int i=0;i<AppVars::urlRSSlist.size();i++){
  7. qDebug() << "enter for loop for i = "+QString::number(i);
  8. AppVars::netManList[i]->get(QNetworkRequest(QUrl(AppVars::urlRSSlist[i])));
  9. }
  10.  
  11. }
  12.  
  13. void Window::downloadedRSSalaune(QNetworkReply* reply){
  14.  
  15. qDebug() << reply->errorString();
  16.  
  17. QByteArray data =QByteArray(reply->readAll());
  18.  
  19. QList<QString> titleList;
  20. QList<QString> linkList;
  21. QDomDocument *domfile = new QDomDocument("alaune_xml");
  22. if(!(domfile->setContent(data))){
  23. return;
  24. }
  25.  
  26. QDomNode principalNode = domfile->documentElement();
  27. QDomNode channelNode = principalNode.namedItem("rss").namedItem("channel");
  28. QDomNodeList listItems = channelNode.childNodes();
  29.  
  30. int k = 0;
  31. int i = 0;
  32. while(k<10 && i<listItems.length()){
  33. if(listItems.at(i).nodeName() == "item"){
  34. qDebug() << listItems.at(i).namedItem("title").toElement().text();
  35. titleList << listItems.at(i).namedItem("title").toElement().text();
  36. linkList << listItems.at(i).namedItem("link").toElement().text();
  37. ++k;
  38. }
  39. ++i;
  40. }
  41.  
  42. firstInsert10ArticlesXML(titleList, linkList, "alaune");
  43.  
  44. tooltipInstantNews("DirectNews France","Les articles sont maintenant à jours.","");
  45. }
  46.  
  47.  
  48. void Window::firstInsert10ArticlesXML(QList<QString> titles, QList<QString> links, QString cat)
  49. {
  50. QString filepath = QCoreApplication::applicationDirPath();
  51. filepath.append("\\history.xml");
  52. AppFiles::historyXML->setFileName(filepath);
  53.  
  54. if(!(AppFiles::historyXML->open(QIODevice::ReadOnly))){
  55. return;
  56. }
  57.  
  58. // QDomDocument to parse xml file
  59. QDomDocument *domfile = new QDomDocument("history_xml");
  60. if(!(domfile->setContent(AppFiles::historyXML))){
  61. return;
  62. }
  63. AppFiles::historyXML->close();
  64.  
  65. QList<QDomElement *> newItems;
  66. for(int i = 0; i<10; i++){
  67. newItems<<new QDomElement(domfile->createElement("item"));
  68.  
  69. QDomElement titleSubItem = domfile->createElement("title");
  70. QDomText titleText = domfile->createTextNode(titles[i]);
  71. QDomElement linkSubItem = domfile->createElement("link");
  72. QDomText linkText = domfile->createTextNode(links[i]);
  73.  
  74. titleSubItem.appendChild(titleText);
  75. linkSubItem.appendChild(linkText);
  76. newItems[i]->appendChild(titleSubItem);
  77. newItems[i]->appendChild(linkSubItem);
  78. }
  79.  
  80. QDomNode principalNode = domfile->documentElement();
  81.  
  82. QDomNode catNode = principalNode.namedItem(cat);
  83.  
  84. if(catNode.isNull())
  85. return;
  86.  
  87. for(int i = 0; i<10; i++){
  88. catNode.insertBefore(*newItems[i],catNode.firstChild());
  89. }
  90.  
  91. QString write_doc = domfile->toString();
  92.  
  93. if(!(AppFiles::historyXML->open(QIODevice::WriteOnly))){
  94. return;
  95. }
  96.  
  97. AppFiles::historyXML->resize(0);
  98. QTextStream stream(AppFiles::historyXML);
  99. stream << write_doc;
  100. AppFiles::historyXML->close();
  101.  
  102. ReadXML();
  103. }
  104.  
  105. void Window::ReadXML()
  106. {
  107. QString filepath = QCoreApplication::applicationDirPath();
  108. filepath.append("\\history.xml");
  109. AppFiles::historyXML->setFileName(filepath);
  110.  
  111. if(!(AppFiles::historyXML->open(QIODevice::ReadOnly))){
  112. return;
  113. }
  114.  
  115. // QDomDocument to parse xml file
  116. QDomDocument *domfile = new QDomDocument("history_xml");
  117. if(!(domfile->setContent(AppFiles::historyXML))){
  118. return;
  119. }
  120. AppFiles::historyXML->close();
  121.  
  122. QDomNode principalNode = domfile->documentElement();
  123.  
  124. QList<QDomNode> listNodes;
  125. listNodes<<principalNode.namedItem("alaune")<<principalNode.namedItem("monde")<<principalNode.namedItem("politique")<<principalNode.namedItem("societesante")
  126. <<principalNode.namedItem("economie")<<principalNode.namedItem("science")<<principalNode.namedItem("art")<<principalNode.namedItem("sport")
  127. <<principalNode.namedItem("people");
  128.  
  129. for(int k=0;k<9;k++){
  130. QDomNode item = listNodes[k].firstChild();
  131. int i = 0;
  132. while(!listNodes[k].isNull() && !item.isNull() && i<10){
  133. //for each article found, enable the QAction, and attribute text and link
  134. listArticles[k][i]->setEnabled(true);
  135. QString titleTrunc = item.namedItem("title").toElement().text();
  136. if(titleTrunc.size() > 50)
  137. titleTrunc = titleTrunc.left(50).append("...");
  138. listArticles[k][i]->setText(titleTrunc);
  139. AppVars::listShortcuts[k][i] = item.namedItem("link").toElement().text();
  140. ++i;
  141. item = item.nextSibling();
  142. }
  143. }
  144. }
  145.  
  146. void Window::tooltipInstantNews(QString title, QString categorie, QString url)
  147. {
  148. // recieved from getrssthread.cpp, show directly (no use of any xml file) the news and attribute system tray message link
  149. sticon->setToolTip(categorie+" : \n"+title);
  150. AppVars::shortcutMessage = url;
  151. if(AppVars::NotifBool)
  152. sticon->showMessage(categorie,title,QSystemTrayIcon::Information);
  153.  
  154. }
To copy to clipboard, switch view to plain text mode 

I may have to put some if(!ERROR) but I don't know where and how.

Window class derivates from QWidget
AppVars::urlRSSlist is a QList<String> (global var)
AppVars::netManList is a QList<QNetworkAccessManager*> (global var)

if something not clear, please tell me.

Thank u in advance for your help.