[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(){
    FileSize[count]=0;
    QNetworkRequest req;
    manager = new QNetworkAccessManager(this);
    req.setUrl(QUrl(UrlList.at(count)));
    reply__ = manager->head(req);
    QEventLoop loop; //edit
    QObject::connect(reply__, SIGNAL(finished()), &loop, SLOT(quit())); //edit
    connect(reply__,SIGNAL(finished()),this,SLOT(num()));
    loop.exec(); //edit
    count++;
    if(count<UrlList.count()) fileSize();
    }
    void MainWindow::num(){
    FileSize[count] = reply__->header(QNetworkRequest::ContentLengthHeader).toUInt();
    reply__->deleteLater();
    manager->deleteLater();
    }
    @

    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
 

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