How to read the contents of the QHTTP file in QString? I want to read the contents of the file in http and am using QHTTP for it. How to read it in QString or any other variables.
Printable View
How to read the contents of the QHTTP file in QString? I want to read the contents of the file in http and am using QHTTP for it. How to read it in QString or any other variables.
Read the data into a QByteArray then, assuming the data is actually text, use either:
How to read the contents from QHTTP in a bytearray?
by using a method that returns a QByteArray. You'll find it in the documentation.
just to mention it the 134281246874th time:
This class is obsolete. It is provided to keep old source code working. We strongly advise against using it in new code.
I am able to write the contents into a file, but unable to write those contents in a variable. Whether it is possible of reading the contents directly to a variable rather than writing to a file and then reading??
Added after 1 29 minutes:
Code:
QNetworkAccessManager *manager = new QNetworkAccessManager(this); connect(manager, SIGNAL(finished(QNetworkReply*)), this, SLOT(replyFinished(QNetworkReply*))); QNetworkReply *reply= manager->get(QNetworkRequest(QUrl("http://www.oczenterprise.com/support/firmware/MN0MTV660VYQ0BGL/release/12606"))); QEventLoop loop; loop.exec(); file.write(reply->readAll()); QByteArray strbytes; strbytes=reply->readAll(); file.close(); ffile.write(strbytes);
In this code, strbytes has nothing. I have used
Are you serious?! :confused:
You use the QHttp::readAll() method that returns a QByteArray (you know, a variable in memory) in the code you just posted. It contains nothing because you read the stream when it is already at the end of file, something that has been pointed out to you before. If you cannot work it out from the QHttp documentation, general programming knowledge, your own code, and the numerous other threads on this same problem then I suggest it is time you sat back and reassessed your programmer aspirations.
A classic facepalm thread :cool:
Attachment 6579
I was just about to post this:
Attachment 6580
because it needs some emphasis... but you and I are obviously tuned into the same meme :D
I had this one bookmarked for the next post but you beat me to it :D
Edit: Sorry, just can't stop laughing :rolleyes: