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.

Recommended Answers

All 11 Replies

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?

Qt IDE for qt programming with C++

What does the Qt documentation say?

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

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.

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?

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.

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;
    }

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

QString current = *it;

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

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.