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

Thiago Macieira thiago.macieira at intel.com
Wed Oct 28 22:43:12 CET 2015


On Thursday 29 October 2015 00:36:08 Igor Mironchik wrote:
> 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...

Avoid doing that. Seeking the stream is an expensive operation since 
QTextStream needs to flush the buffers, reposition the device and reconvert 
the input into UTF-16 without Carriage Return.

I don't know what happens if you position it after the CR but before the LF. I 
know what happens if you position in the middle of a multibyte sequence: the 
first character you'll read will be either mojibake or the Unicode Replacement 
Character (U+FFFD).

-- 
Thiago Macieira - thiago.macieira (AT) intel.com
  Software Architect - Intel Open Source Technology Center




More information about the Interest mailing list