| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- #ifndef APP_CURLFUNC_H
- #define APP_CURLFUNC_H
- #include <QObject>
- #include <QString>
- #include <curl/curl.h>
- #include <QFuture>
- #include <QQueue>
- #include <QAtomicInt>
- class CurlFtpUploader : public QObject
- {
- Q_OBJECT
- public:
- explicit CurlFtpUploader(QObject *parent = nullptr);
- ~CurlFtpUploader();
- // 设置 FTP 参数
- void setFtpParams(const QString &username,
- const QString &password,
- const QString &host,
- int port,
- const QString &remotePath);
- // 异步上传文件(非阻塞)
- //void uploadFileAsync(const QString &localFilePath);
- public slots:
- void uploadFilesAsync(const QStringList &filePaths);
- signals:
- void progressChanged(double uploadedPercent); // 进度百分比 (0.0 ~ 100.0)
- void progressChanged_file(const QString ¤tFile, double percent);
- void finished(bool success, const QString &error); // 完成信号
- void allUploadsFinished();
- void fileUploaded(const QString &filePath);
- private:
- QMutex m_queueMutex;
- QQueue<QString> m_uploadQueue;
- QString m_currentUploadingFile;
- void processNextFile();
- // 静态回调函数(供 CURL 调用)
- static size_t readCallback(char *buffer, size_t size, size_t nitems, void *userdata);
- static int progressCallback(void *clientp, curl_off_t dltotal, curl_off_t dlnow, curl_off_t ultotal, curl_off_t ulnow);
- // 内部上传逻辑
- void performUpload(const QString &localFilePath);
- QFuture<void> ftp_Thread;
- // FTP 参数
- QString m_username;
- QString m_password;
- QString m_host;
- int m_port;
- QString m_remotePath;
- };
- #endif // APP_CURLFUNC_H
|