fork download
  1. #include "ImgD.h"
  2.  
  3. #include <QWebElementCollection>
  4. #include <QWebFrame>
  5.  
  6. ImgD::ImgD() :
  7. QObject()
  8. {
  9. connect(&m_WebCtrl, SIGNAL(finished(QNetworkReply*)),
  10. SLOT(fileDownloaded(QNetworkReply*)));
  11.  
  12. urlEdit = new QLineEdit;
  13. button = new QPushButton("Download");
  14. connect(button,SIGNAL(clicked()),SLOT(download()));
  15. info = new QLabel;
  16.  
  17. QBoxLayout* mainLayout = new QBoxLayout(QBoxLayout::TopToBottom);
  18. mainLayout -> addWidget(urlEdit);
  19. mainLayout -> addWidget(button);
  20. mainLayout -> addWidget(info);
  21. widg.setLayout(mainLayout);
  22.  
  23. connect(&view,SIGNAL(loadFinished(bool)),SLOT(startDownload(bool)));
  24. connect(&view,SIGNAL(loadStarted()),SLOT(start()));
  25. connect(this, SIGNAL(downloaded(QString)), SLOT(loadImage(QString)));
  26. }
  27.  
  28. ImgD::~ImgD()
  29. {
  30.  
  31. }
  32.  
  33. void ImgD::fileDownloaded(QNetworkReply* pReply)
  34. {
  35. m_DownloadedData = pReply->readAll();
  36. pReply->deleteLater();
  37. emit downloaded((pReply -> url()).toString());
  38. }
  39.  
  40. void ImgD::download()
  41. {
  42. url = new QUrl(urlEdit -> text());
  43.  
  44. view.load(*url);
  45. }
  46.  
  47. void ImgD::start()
  48. {
  49. info -> setText("STARTED");
  50. }
  51.  
  52. void ImgD::startDownload(bool)
  53. {
  54. QString base = (urlEdit -> text()).left( (urlEdit -> text()).indexOf("/",8) );
  55.  
  56. QWebElementCollection links;
  57. links = view.page()->mainFrame()->findAllElements("a[name='expandfunc']");
  58.  
  59. foreach (QWebElement paraElement, links)
  60. {
  61. QString imageUrl = base + paraElement.attribute("href");
  62. info -> setText( info -> text() + "\ndownloading.." + imageUrl);
  63. QNetworkRequest request(imageUrl);
  64. m_WebCtrl.get(request);
  65. }
  66.  
  67. }
  68.  
  69. void ImgD::loadImage(QString name)
  70. {
  71. QPixmap image;
  72. name = name.right(name.size() - name.lastIndexOf("/") - 1);
  73. info -> setText( info -> text() + "\nsaving.." + name);
  74. image.loadFromData(m_DownloadedData);
  75. (image.toImage()).save(name);
  76. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:1:18: fatal error: ImgD.h: No such file or directory
 #include "ImgD.h"
                  ^
compilation terminated.
stdout
Standard output is empty