networkdownloader.h 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #ifndef INCLUDEILEDOWNLOADER_H
  2. #define INCLUDEILEDOWNLOADER_H
  3. #include <QObject>
  4. #include <QNetworkAccessManager>
  5. #include <QNetworkRequest>
  6. #include <QNetworkReply>
  7. #include <QFile>
  8. #include <QByteArray>
  9. class NetworkDownloader : public QObject
  10. {
  11. Q_OBJECT
  12. public:
  13. explicit NetworkDownloader(QObject *parent = 0);
  14. virtual ~NetworkDownloader();
  15. QUrl getUrl();
  16. void setUrl(const QUrl& _url);
  17. void waitForDownloaded();
  18. signals:
  19. void downloadFinished();
  20. void progressChanged(qint64 bytesReceived, qint64 bytesTotal);
  21. public slots:
  22. void start();
  23. void updateDownloadSpeedLimit(int bytes_per_sec);
  24. void stop();
  25. private slots:
  26. void onDownloadFinished(QNetworkReply* pReply);
  27. void onReadyRead();
  28. public:
  29. QFile* targetFile {nullptr};
  30. QByteArray* targetBytearray {nullptr};
  31. private:
  32. bool busy;
  33. QUrl url;
  34. QNetworkReply* m_CurrentReply {nullptr};
  35. QNetworkAccessManager m_WebCtrl;
  36. unsigned download_speed_limit {0};
  37. };
  38. #endif // INCLUDEILEDOWNLOADER_H