httpdownload.h 917 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #ifndef HTTPDOWNLOAD_H
  2. #define HTTPDOWNLOAD_H
  3. #include "SNCCore_global.h"
  4. #include <QObject>
  5. #include <QNetworkAccessManager>
  6. #include <QUrl>
  7. #include <QtNetwork>
  8. QT_BEGIN_NAMESPACE
  9. class QFile;
  10. class QSslError;
  11. class QAuthenticator;
  12. class QNetworkReply;
  13. QT_END_NAMESPACE
  14. class SNCCORESHARED_EXPORT HttpDownload : public QObject
  15. {
  16. Q_OBJECT
  17. public:
  18. explicit HttpDownload(QObject *parent = 0);
  19. ~HttpDownload();
  20. int downloadFile(QString fileUrl,QString savePath);
  21. private:
  22. void startRequest(QUrl url);
  23. private slots:
  24. void httpFinished();
  25. void httpReadyRead();
  26. void updateDataReadProgress(qint64 bytesRead, qint64 totalBytes);
  27. private:
  28. QUrl url;
  29. QNetworkAccessManager qnam;
  30. QNetworkReply *reply;
  31. QFile *file;
  32. bool httpRequestAborted;
  33. QEventLoop loop;
  34. int retCode ;
  35. bool finish ;
  36. };
  37. #endif // HTTPDOWNLOAD_H