QtHttps.h 990 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #ifndef QTHTTPS_H
  2. #define QTHTTPS_H
  3. #include <QObject>
  4. #include <QNetworkReply>
  5. #include <QNetworkAccessManager>
  6. #include <QNetworkRequest>
  7. #include <QFile>
  8. class QtHttps : public QObject
  9. {
  10. Q_OBJECT
  11. public:
  12. explicit QtHttps(QObject *parent = nullptr);
  13. ~QtHttps();
  14. bool Get(const QString &url);
  15. bool GetHead(const QString &url);
  16. void Post(const QString &url, const QByteArray &data);
  17. void downloadFile(const QString &url, const QString &filePath);
  18. signals:
  19. void signal_replyFinished();
  20. void signal_downloadProgress(qint64 bytesReceived, qint64 bytesTotal);
  21. private slots:
  22. void do_replyFinished();
  23. void do_replyReadyRead();
  24. void do_downloadProgress(qint64 bytesReceived, qint64 bytesTotal);
  25. void do_error(QNetworkReply::NetworkError code);
  26. private:
  27. QNetworkAccessManager *m_manager = nullptr;
  28. QNetworkReply *m_reply = nullptr;
  29. QFile *m_file = nullptr; /* 保存临时文件 */
  30. };
  31. #endif /* QTHTTPS_H */