Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED]Problem with sending multiple requests.
Forum Updated to NodeBB v4.3 + New Features

[SOLVED]Problem with sending multiple requests.

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 766 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    SetBetterPass
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved