#ifndef DOWNLOADWORKER_H #define DOWNLOADWORKER_H #include #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); public slots: void doWork(); void dataReady(); signals: void resultReady(int identifier, QByteArray data); void testSignals(); private: int identifier; QString url; QPair range; QNetworkReply *reply; }; 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, qint64 fileSize); void paruseDownload(); void stopDownload(); public slots: void handleResults(int identifier, QByteArray data); // void handleTest(); signals: void operate(const QString &url, const QPair &downloadRange); void errorOccur(const QString& msg); void receivedProcess(qint64 number); private: int threadNum; QString filename; QVector> ranges; QFile file; qint64 bytesReceived; QVector writePosList; QMutex mutex; }; #endif // FILEDOWNLOADWORKER_H