Results 1 to 8 of 8

Thread: How to download using QHttp?

  1. #1
    Join Date
    Mar 2011
    Location
    Coimbatore,TamilNadu,India
    Posts
    382
    Thanks
    10
    Thanked 13 Times in 12 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default How to download using QHttp?

    How to download using QHttp? But file should not be saved in the local hard disk, It has to save in some memory variable, How to to this?

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: How to download using QHttp?

    Don't use QHttp in new code. To quote the docs:
    This class is obsolete. It is provided to keep old source code working. We strongly advise against using it in new code.
    You use QNetworkAccessManager and QNetworkReply::read() or readAll() the data into a QByteArray

  3. #3
    Join Date
    Mar 2011
    Location
    Coimbatore,TamilNadu,India
    Posts
    382
    Thanks
    10
    Thanked 13 Times in 12 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to download using QHttp?

    I have used QHttp for downloading it, now the file is being downloaded , and saved in the local disk, But i just want to read that file, storing it in a variable, and not saving it as a file in local hard disk. How to perform this with QHttp??

  4. #4
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to download using QHttp?

    I'd use readAll rather than specifying the i/o device in the request.

    But as ChrisW67 says, you should be using QNetworkAccessManager, as QHttp is deprecated.

  5. #5
    Join Date
    Mar 2011
    Location
    Denmark
    Posts
    74
    Thanks
    7
    Thanked 10 Times in 9 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: How to download using QHttp?

    Check out the "HTTP Client" example.

    on the QNetworkReply::finished signal call reply->readAll() if the data is human readable you can do something like
    Qt Code:
    1. QString replyString;
    2. if (reply->isReadable())
    3. {
    4. replyString = QString::fromUtf8(reply->readAll().data());
    5. }
    To copy to clipboard, switch view to plain text mode 

  6. #6
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: How to download using QHttp?

    Quote Originally Posted by Gokulnathvc View Post
    I have used QHttp for downloading it, now the file is being downloaded , and saved in the local disk, But i just want to read that file, storing it in a variable, and not saving it as a file in local hard disk. How to perform this with QHttp??
    Even if you persist in using the obsolete class you can use QHttp::readAll() to put the data into a QByteArray (either bit-by-bit using in response to readyRead(), or all at once in response to finished()). That is, use exactly the same method as used in the HTTP Example. This information really easy to find if you read the docs and work through the examples (until you understand them).

  7. #7
    Join Date
    Mar 2011
    Location
    Coimbatore,TamilNadu,India
    Posts
    382
    Thanks
    10
    Thanked 13 Times in 12 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to download using QHttp?

    How to read the whole file at once using readAll()?

  8. #8
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: How to download using QHttp?

    Wait until the QNetworkReply::finished() or QNetworkAccessManager::finished() signal is emitted and then call readAll(). If you are still using QHttp then you can work out the equivalent for yourself.

    If your file is large, or you don't know its size, then trying to hold the whole thing in memory might be a mistake.

Similar Threads

  1. Problem with QHttp / HTML source download
    By hojoff79 in forum Qt Programming
    Replies: 4
    Last Post: 21st January 2011, 08:20
  2. How to limit download speed with QHttp ?
    By THRESHE in forum Qt Programming
    Replies: 6
    Last Post: 25th November 2010, 11:55
  3. Resume download with QHttp
    By THRESHE in forum Qt Programming
    Replies: 7
    Last Post: 17th April 2010, 10:12
  4. Qhttp Get file size in Link download
    By nhs_0702 in forum Qt Programming
    Replies: 2
    Last Post: 17th April 2010, 09:24
  5. QHttp download file problem.
    By fengtian.we in forum Qt Programming
    Replies: 12
    Last Post: 12th June 2007, 09:39

Tags for this Thread

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.