how to download multi files in same time with multi Progress bar



  • hi
    how to download multi files in same time & each download have a Progress bar


  • Moderators

    Here's an example you can use as a starting point:

    #include <QApplication>
    #include <QProgressBar>
    #include <QNetworkAccessManager>
    #include <QNetworkRequest>
    #include <QNetworkReply>
    
    int main(int argc, char *argv[]) {
        QApplication a(argc, argv);
    
        QNetworkAccessManager nam;
    
        for( int i=0; i < 3; ++i) {
            auto reply = nam.get(QNetworkRequest(QUrl("http://whatever")));
            auto progress = new QProgressBar();
            progress->move(100, 100 * i);
            progress->show();
    
            QObject::connect(reply, &QNetworkReply::finished, progress, &QProgressBar::deleteLater);
            QObject::connect(reply, &QNetworkReply::downloadProgress, [=](qint64 bytes, qint64 total){
                progress->setRange(0, total);
                progress->setValue(bytes);
            });
        }
    
        return a.exec();
    }
    

    You can of course put the bars in some layout of some other widget, but I hope you get the idea.



  • @Chris-Kawa thank you but i don't know how to use this code in my project : https://github.com/ARASHz4/Advanced_Downloader
    download is in class downloader.cpp
    Please help me i have no idea to do this.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.