Results 1 to 4 of 4

Thread: Downloading Pdf's from the web using QNetworkAccessManager.

  1. #1
    Join Date
    Jul 2012
    Posts
    201
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    26
    Thanked 1 Time in 1 Post

    Default Downloading Pdf's from the web using QNetworkAccessManager.

    I've got a program that is supposed to download a list of pdf documents from the web using QNetworkAccessManager. I have a QStringList of pdf urls and my problem is getting QNetworkAccessManager to download 6 pdf's at a time, when I try implementing this, the program keeps downloading the first url on the list 6 times. What could be causing this?
    Qt Code:
    1. void CPT_Page::getPdf(QStringList linksList)
    2. {
    3. qDebug() << linksList <<endl;
    4. for(int i = 0; i < linksList.size(); i++)
    5. {
    6. download_request_list.append(QNetworkRequest(QUrl(QString("http://web1.capetown.gov.za%1").arg(linksList.at(i)))));
    7. download_replies_list.append(nManager->get(download_request_list.at(i)));
    8. connect(download_replies_list.at(i), SIGNAL(finished()), this, SLOT(downloadAttachment()));
    9. }
    10.  
    11. }
    12.  
    13. void CPT_Page::downloadAttachment()
    14. {
    15. static int fileNum = 1;
    16. QFile tempFile(QString("C:/Users/C5248134/Desktop/Projects/Ithala/Include/Sourced_Tenders/temp%1.pdf").arg(fileNum));
    17. fileNum++;
    18.  
    19. if(!tempFile.open(QFile::WriteOnly))
    20. qDebug() << "File did not open" <<endl;
    21. QDataStream outStream(&tempFile);
    22.  
    23. outStream << download_replies_list.at(0)->readAll() <<endl;
    24. download_replies_list.clear();
    25. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts

    Default Re: Downloading Pdf's from the web using QNetworkAccessManager.

    Line 23 always accesses index 0, i.e. the first download reply.

    Maybe just connect to the QNAM's finished signal instead of storing the replies in a list?
    Or do yoo need to cancel them?

    Cheers,
    _

  3. #3
    Join Date
    Jul 2012
    Posts
    201
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    26
    Thanked 1 Time in 1 Post

    Default Re: Downloading Pdf's from the web using QNetworkAccessManager.

    thank you for your reply. just one question though. Can the QNM objects handle multiple different requests at a time. I am asking because even when I connect the QNM finished signal to CPT_Page::downloadAttachment() slot, I still get the same pdf document multiple time. I guess what I am asking is that can QNM::get() perform another request while it hasn't finished with the first request.

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts

    Default Re: Downloading Pdf's from the web using QNetworkAccessManager.

    Yes, QNAM handles multiple requests concurrently.
    I think the limit is 6 per host, but you can enqueue many more.

    Cheers,
    _

Similar Threads

  1. Replies: 3
    Last Post: 12th September 2015, 20:13
  2. Replies: 3
    Last Post: 27th June 2015, 05:00
  3. Downloading XML file
    By Abdeljalil in forum Qt Programming
    Replies: 2
    Last Post: 24th August 2014, 23:22
  4. Downloading a page with QNetworkAccessManager
    By TempleClause in forum Qt Programming
    Replies: 2
    Last Post: 1st October 2012, 21:58
  5. Downloading multiple files using QNetworkAccessManager
    By aurorius in forum Qt Programming
    Replies: 3
    Last Post: 7th August 2009, 11:51

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.