[Interest] QFile::size() and QTextStream::pos()

Igor Mironchik igor.mironchik at gmail.com
Wed Oct 28 22:36:08 CET 2015



On 29.10.2015 00:17, Thiago Macieira wrote:
> On Thursday 29 October 2015 00:12:14 Igor Mironchik wrote:
>> Thank you, guys. But this question doesn't matter for me more, because I
>> need to calculate line number in the file when reading. That mean that I
>> have to skip white spaces by hand...
> Why don't you use readLine() instead and keep your count?

Well, I thought about it. File reading will be more effective, but 
parsing code will be more complex. When reading char by char I can 
simple skip comment and stay stream at the end of the comment position, 
I can just read one word... With readLine() I have to parse read line, 
if I found that not all is on this line I have to read another, I have 
to store current position on buffered line...

It's not so simple question...

>
>> But you pointed me to another very important question... What about some
>> function isLineEnding()? I can use Separator_Line to detect line ending
>> symbol. But how will be read \r\n - line ending on Windows (other OSes)
>> with QTextStream? Will be it one QChar or two different?
> QTextStream automatically converts \r\n to a single \n.

This is good, but what if I need to seek stream to the one character 
back position? Can I simple write

stream.seek( stream.pos() - 1 );

or I have to keep in mind codec? If so how can I seek to one character 
back position and don't worry about codecs, etc...

-- 
Best Regards,
Igor Mironchik.




More information about the Interest mailing list