#ifndef DOWNLOADWORKER_H #define DOWNLOADWORKER_H #include #include #include #include class DownloadWorker : public QObject { Q_OBJECT public: explicit DownloadWorker(QObject *parent = nullptr); void setIdentifier(int identifier); void setParamter(const QString &url, QPair range, QFile *flle); qint64 getReceivedPos(); public slots: void doWork(); void doStop(); void dataReady(); void slotFinish(); void handleProcess(qint64, qint64); private: int identifier; QString url; qint64 startPos; qint64 endPos; qint64 receivedPos = 0; QNetworkReply *reply; QNetworkAccessManager *mgr; QFile *file; signals: void resultReady(int identifier, QByteArray data); void testSignals(); void workFinished(); void downloadProcess(); }; class DownloadController : public QObject { Q_OBJECT public: explicit DownloadController(QObject *parent = nullptr); ~DownloadController(); void setFilename(QString filename); void setThreadNum(int threadNum); void startDownload(const QString &url); void stopDownload(); qint64 getFileSize(const QString& url); QString replaceDomain(const QString& url, const QString domain); private: int threadNum; QString filename; qint64 fileSize; QVector> ranges; QFile *file; QList workers; int finish = 0; QVector domains; public slots: void handleProcess(); void chunkDownloadFinish(); signals: void errorOccur(const QString& msg); void downloadProcess(qint64, qint64); void downloadFinished(); }; #endif // FILEDOWNLOADWORKER_H