Results 1 to 3 of 3

Thread: Read contents from the file using QHTTP Read()?

  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 Read contents from the file using QHTTP Read()?

    I am using the following code to read the contents from the file using QHTTP.


    Qt Code:
    1. QHttp http;
    2. pad.resize(40);
    3. buf.append(pad);
    4. //buf +=file.read(segFileSize);
    5. http.read(pad.data(),segFileSize);
    To copy to clipboard, switch view to plain text mode 

    How to read the data depending upon the size given in the Read() function.

  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

    Arrow Re: Read contents from the file using QHTTP Read()?

    Groan... Here we go again.

    The QHttp class is obsolete. Do not use it in new code. Why do you continue to ignore advice to move to using QNetworkAccessManager and QNetworkReply?

    The problem is trivially easy even using the wrong API. You could do this to read exactly a number of bytes:
    Qt Code:
    1. // QHttp *http;
    2. // QByteArray ba;
    3. qint64 available = http->bytesAvailable();
    4. ba.resize(available);
    5. qint64 justRead = http->read(ba.data(), available);
    6. if (justRead != available)
    7. // error condition of some sort
    8. ...;
    To copy to clipboard, switch view to plain text mode 
    or more simply this in your readyRead() signal handler (which is called only when there is data available) or requestFinished() signal handler:
    Qt Code:
    1. QByteArray ba = http->readAll();
    To copy to clipboard, switch view to plain text mode 

    Of course, if you bothered to read your previous posts on the topic you might worked this out weeks ago.

  3. #3
    Join Date
    Oct 2010
    Location
    Berlin, Germany
    Posts
    358
    Thanks
    18
    Thanked 68 Times in 66 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Read contents from the file using QHTTP Read()?

    you don't have to create a new thread every day for the same topic.

Similar Threads

  1. Read from a zip file
    By rajji_saini in forum Qt Programming
    Replies: 2
    Last Post: 21st June 2011, 01:28
  2. Replies: 8
    Last Post: 17th June 2011, 01:35
  3. Read from a file
    By matulik in forum Newbie
    Replies: 4
    Last Post: 26th April 2010, 20:02
  4. Read the file into
    By offline in forum Qt Programming
    Replies: 7
    Last Post: 12th April 2010, 13:11
  5. Read An Xml File
    By Alienxs in forum Qt Programming
    Replies: 3
    Last Post: 5th January 2007, 01:28

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.