app_curlFunc.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #ifndef APP_CURLFUNC_H
  2. #define APP_CURLFUNC_H
  3. #include <QObject>
  4. #include <QString>
  5. #include <curl/curl.h>
  6. class CurlFtpUploader : public QObject
  7. {
  8. Q_OBJECT
  9. public:
  10. explicit CurlFtpUploader(QObject *parent = nullptr);
  11. ~CurlFtpUploader();
  12. // 设置 FTP 参数
  13. void setFtpParams(const QString &username,
  14. const QString &password,
  15. const QString &host,
  16. int port,
  17. const QString &remotePath);
  18. // 异步上传文件(非阻塞)
  19. void uploadFileAsync(const QString &localFilePath);
  20. signals:
  21. void downloadStart(const QString &tips);
  22. void progressChanged(double uploadedPercent, const QString &filePath); // 进度百分比 (0.0 ~ 100.0) 与上传文件路径
  23. void finished(bool success, const QString &error); // 完成信号
  24. void sglProgress(double val,double timeLeft,double speed); //进度信号
  25. private:
  26. // 静态回调函数(供 CURL 调用)
  27. static size_t readCallback(char *buffer, size_t size, size_t nitems, void *userdata);
  28. static int progressCallback(void *clientp, curl_off_t dltotal, curl_off_t dlnow, curl_off_t ultotal, curl_off_t ulnow);
  29. // 内部上传逻辑
  30. void performUpload(const QString &localFilePath);
  31. // FTP 参数
  32. QString m_username;
  33. QString m_password;
  34. QString m_host;
  35. int m_port;
  36. QString m_remotePath;
  37. QString update_type;
  38. QString m_currentFilePath; // 当前正在上传的文件路径,用于进度信号携带
  39. };
  40. #endif // APP_CURLFUNC_H