Important: Please read the Qt Code of Conduct -

[SOLVED]Problem with sending multiple requests.

  • I am trying to get information about size of files from url list. So I made recursive function that will send head request for each url in my list. Everything go fine if there is only one url in my list, function returns file size and program continues. But as soon as there is more than one url in list and function is called again to get another file size the problem occurs. The code:
    void MainWindow::fileSize(){
    QNetworkRequest req;
    manager = new QNetworkAccessManager(this);
    reply__ = manager->head(req);
    QEventLoop loop; //edit
    QObject::connect(reply__, SIGNAL(finished()), &loop, SLOT(quit())); //edit
    loop.exec(); //edit
    if(count<UrlList.count()) fileSize();
    void MainWindow::num(){
    FileSize[count] = reply__->header(QNetworkRequest::ContentLengthHeader).toUInt();

    The problem is if(count<UrlList.count()) fileSize(); calls fileSize() function before finished() signal is called so it calls function until count isn't equal UrlList.count() and then connects num() slot which causes my program crashes. So I have to stop program somehow before finished() slot is called and then continue. I tried to add QTimer there but it didn't work. Anyone can help?
    Thanks for any reply.

    edit: OK used google and find the problem, needed to add eventloop

Log in to reply