Results 1 to 16 of 16

Thread: Issue with download from url

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2015
    Posts
    185
    Thanks
    5
    Qt products
    Qt5
    Platforms
    MacOS X Windows

    Default Re: Issue with download from url

    Now I am able to download and write all the content using the readyRead()
    Qt Code:
    1. m_reply = m_manager->get(m_request);
    2.  
    3. connect(m_reply,SIGNAL(readyRead()),this,SLOT(readingReadyBytes()));
    4.  
    5.  
    6. void zoushoFtpTransfer::readingReadyBytes()
    7. {
    8. QFile file(m_localPath);
    9. file.open(QIODevice::writeOnly);
    10. file.write(m_reply->read(m_reply->bytesAvailable()));
    11. file.close();
    12. qDebug()<<"size : "<<file.size();
    13. m_isDownloadSccess = true;
    14. }
    To copy to clipboard, switch view to plain text mode 

    Again there is one more issue, after writing onto file, I am storing all the data for that file in QByteArray.
    Its storing in QBytearray till 134459022 of data, after which bad_alloc error is thrown.

    Let me know what data type can be used to store all the 318459022 size of data

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

    Default Re: Issue with download from url

    Quote Originally Posted by ejoshva View Post
    Let me know what data type can be used to store all the 318459022 size of data
    It is not a matter of data type. QByteArray can easily handle that, your system can't.

    Cheers,
    _

  3. #3
    Join Date
    Oct 2009
    Posts
    483
    Thanked 97 Times in 94 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Issue with download from url

    This last snippet of code you posted is exactly the same as the previous one, and suffers from exactly the same problems that were pointed to you. Since you claim to have now solved these problems, I suppose that this code is irrelevant to your new question.

    If you have understood that you could not keep the whole file in memory before writing it to disk in one go, it should come as no surprise that attempting to completely load it in memory fails for the same reason.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Issue with download from url

    Quote Originally Posted by ejoshva View Post
    Now I am able to download and write all the content using the readyRead()
    Qt Code:
    1. m_reply = m_manager->get(m_request);
    2.  
    3. connect(m_reply,SIGNAL(readyRead()),this,SLOT(readingReadyBytes()));
    4.  
    5.  
    6. void zoushoFtpTransfer::readingReadyBytes()
    7. {
    8. QFile file(m_localPath);
    9. file.open(QIODevice::writeOnly);
    10. file.write(m_reply->read(m_reply->bytesAvailable()));
    11. file.close();
    12. qDebug()<<"size : "<<file.size();
    13. m_isDownloadSccess = true;
    14. }
    To copy to clipboard, switch view to plain text mode 

    Again there is one more issue, after writing onto file, I am storing all the data for that file in QByteArray.
    Its storing in QBytearray till 134459022 of data, after which bad_alloc error is thrown.

    Let me know what data type can be used to store all the 318459022 size of data
    I'll give you a hint:

    7 = 4+3 // to read 7MB, read 4MB and then 3
    10 = 4+4+2 // to read 10MB read 4MB, then again 4MB and then 2 MB
    445 = 4+...+4+1 // to read 445MB read 4MB as long as there is more than 4MB to read and then read whatever remains

    And another hint:

    If you tell read() to read 4MB but there is only 1MB available, it will read 1MB

    Question:

    How much memory is needed to read 445MB of data this way?

    Now go and carve an algorithm out of it.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. The following user says thank you to wysota for this useful post:

    ejoshva (20th April 2015)

  6. #5
    Join Date
    Feb 2015
    Posts
    185
    Thanks
    5
    Qt products
    Qt5
    Platforms
    MacOS X Windows

    Default Re: Issue with download from url

    Thanks for your replies.

    @wysota - will try out an algorithm based on your hints

    Quote Originally Posted by wysota View Post
    I'll give you a hint:

    7 = 4+3 // to read 7MB, read 4MB and then 3
    10 = 4+4+2 // to read 10MB read 4MB, then again 4MB and then 2 MB
    445 = 4+...+4+1 // to read 445MB read 4MB as long as there is more than 4MB to read and then read whatever remains

    And another hint:

    If you tell read() to read 4MB but there is only 1MB available, it will read 1MB

    Question:

    How much memory is needed to read 445MB of data this way?

    Now go and carve an algorithm out of it.
    ans : 4 MB

Similar Threads

  1. How to download the source in the URL
    By zgulser in forum Qt Programming
    Replies: 1
    Last Post: 26th April 2012, 09:29
  2. From where should I download QML
    By prajnaranjan.das in forum Qt Programming
    Replies: 1
    Last Post: 10th February 2011, 19:54
  3. where download kd chart2.2
    By yunpeng880 in forum General Discussion
    Replies: 3
    Last Post: 13th January 2009, 08:45
  4. Download Manager Like IDM(Internet Download Manager)
    By sathiskumarmsk in forum Qt Programming
    Replies: 1
    Last Post: 27th July 2008, 15:52
  5. i need to download qt-vsintegration
    By mmg123 in forum Installation and Deployment
    Replies: 4
    Last Post: 15th October 2006, 14:20

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.