954,499 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Difference between readAll(), read(), readLine()?

Hi guys. I am a bit confused among the following three functions.

read()
readAll()
readLine()

How do they work? I'll be really thankful to you all.

Thanks alot for your precious time!

Regards.

C++ programmer
Light Poster
28 posts since Jan 2012
Reputation Points: 10
Solved Threads: 0
 

None of those are standard C++ functions. What library are you using to get them, or what compiler are you using if they're extended library functions?

deceptikon
Indubitably
Administrator
632 posts since Jan 2012
Reputation Points: 119
Solved Threads: 105
 

Qt IDE for qt programming with C++

C++ programmer
Light Poster
28 posts since Jan 2012
Reputation Points: 10
Solved Threads: 0
 

What does the Qt documentation say?

deceptikon
Indubitably
Administrator
632 posts since Jan 2012
Reputation Points: 119
Solved Threads: 105
 

Documentation says it better than I could.
You can click on the hyperlinks to get directly to each explanation.

thines01
Postaholic
Team Colleague
2,424 posts since Oct 2009
Reputation Points: 445
Solved Threads: 402
 

I concluded that, readAll() reads every thing in the file. same goes for read(). But what is meant by "Reads at most maxlen characters from the stream".

for example i have saved the comments of some people in a file directly from the program i made. Each user before commenting is bound to type a special character at the start of comment. Now i want to load all the comments one by one in a Qlabel from that file. How can i recognise that the special character in the file has reached so that i can print the next Comment on another Qlabel.

C++ programmer
Light Poster
28 posts since Jan 2012
Reputation Points: 10
Solved Threads: 0
 

If you give it a maxlen value, that's all it will read.
If you set the parameter to 10, it will read 10 characters from the stream.

Since it sounds like the amount of data the user can type is of variable length and that you recognize the next comment by a special character, I suggest you readAll() and then parse the QString (if it's not too much data).

If the amount you're trying to read is too much, you would need to read() the data based on the amount you can process at any time and parse that data based on the location of the special character. Any incomplete comment records would need to be joined totether.

Is that what you meant?

thines01
Postaholic
Team Colleague
2,424 posts since Oct 2009
Reputation Points: 445
Solved Threads: 402
 
But what is meant by "Reads at most maxlen characters from the stream".
If you give it a maxlen value, that's all it will read. If you set the parameter to 10, it will read 10 characters from the stream.


It will read up to 10 characters, but never any more. If there are fewer than 10 characters in the stream then they'll all be read. That's what 'at most' means in this context.

deceptikon
Indubitably
Administrator
632 posts since Jan 2012
Reputation Points: 119
Solved Threads: 105
 

why does the IDE gives me error.

for(QStringList::Iterator it=list.begin();it!=list.end();it++)
{
QString current= it; // here is the error
qDebug()<< current;
}

C++ programmer
Light Poster
28 posts since Jan 2012
Reputation Points: 10
Solved Threads: 0
 

I'd guess that you forgot to dereference the iterator:

QString current = *it;
deceptikon
Indubitably
Administrator
632 posts since Jan 2012
Reputation Points: 119
Solved Threads: 105
 

so it means any kind of list i use, its iterator will return the pointer of the nodes of the list..

C++ programmer
Light Poster
28 posts since Jan 2012
Reputation Points: 10
Solved Threads: 0
 
so it means any kind of list i use, its iterator will return the pointer of the nodes of the list..


Not really. It means that iterators in C++, at least the ones following convention, are an abstraction of pointers. They overload operators in such a way that they have a subset of pointer operations depending on the type of iterator. All iterators have a dereference operator to access the "pointed to" object.

deceptikon
Indubitably
Administrator
632 posts since Jan 2012
Reputation Points: 119
Solved Threads: 105
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: