[Interest] QFile::size() and QTextStream::pos()
Thiago Macieira
thiago.macieira at intel.com
Fri Oct 30 00:40:43 CET 2015
On Friday 30 October 2015 00:08:54 Elvis Stansvik wrote:
> > Slow? This is not the main problem. The main problem is that that seek()
> > and pos() uses device's units. But I need to seek() one character back,
> > and what then just -1, or -2, or something else? unget() can't be
> > implemented with methods of QTextStream.
>
> Sorry if I'm missing something, but wouldn't you have that problem
> with std::istream::unget as well? It operates on chars (bytes).
istream operates on bytes, but QTextStream doesn't. QTextStream's internal
buffer has already applied QTextCodec to convert from the raw binary format to
Unicode (UTF-16). The number of codepoints you've read (# of QChars) and the
number of bytes may not match at all.
If you wanted to do a codec conversion with istream, you'd do it on top, not
below. Note that wistream classes (like wifstream) don't convert from 8-bit to
wchar_t: they read wchar_t from the input. I don't know how to convert from
(say) UTF-8 to UTF-16 or UCS-4 with istream, so you'd probably have to
implement this by yourself and you might find the unget() functionality useful
to unread incomplete multibyte sequences.
--
Thiago Macieira - thiago.macieira (AT) intel.com
Software Architect - Intel Open Source Technology Center
More information about the Interest
mailing list