PDA

View Full Version : Read contents from the file using QHTTP Read()?



Gokulnathvc
21st June 2011, 07:04
I am using the following code to read the contents from the file using QHTTP.



QHttp http;
QByteArray buf;
QByteArray pad;
pad.resize(40);
buf.append(pad);
//buf +=file.read(segFileSize);
http.read(pad.data(),segFileSize);

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

ChrisW67
21st June 2011, 08:23
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:


// QHttp *http;
// QByteArray ba;
qint64 available = http->bytesAvailable();
ba.resize(available);
qint64 justRead = http->read(ba.data(), available);
if (justRead != available)
// error condition of some sort
...;

or more simply this in your readyRead() signal handler (which is called only when there is data available) or requestFinished() signal handler:


QByteArray ba = http->readAll();


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

FelixB
21st June 2011, 09:03
you don't have to create a new thread every day for the same topic.