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.
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:
Qt Code:
// QByteArray ba // or one of the other variantsTo copy to clipboard, switch view to plain text mode
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:
Qt 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);To copy to clipboard, switch view to plain text mode
In this code, strbytes has nothing. I have usedQt Code:
QByteArray strbytes; strbytes=reply->readAll();To copy to clipboard, switch view to plain text mode
Last edited by Gokulnathvc; 16th June 2011 at 11:56.
Are you serious?!
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.
Last edited by ChrisW67; 17th June 2011 at 01:24.
A classic facepalm thread
facepalm.jpg
Last edited by wysota; 17th June 2011 at 01:26.
I was just about to post this:
doublefacepalm.jpg
because it needs some emphasis... but you and I are obviously tuned into the same meme![]()
I had this one bookmarked for the next post but you beat me to it
Edit: Sorry, just can't stop laughing![]()
Bookmarks