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

Igor Mironchik igor.mironchik at gmail.com
Fri Oct 30 00:27:28 CET 2015



On 30.10.2015 02:08, Elvis Stansvik wrote:
> 2015-10-29 23:43 GMT+01:00 Igor Mironchik <igor.mironchik at gmail.com>:
>>
>> On 30.10.2015 00:05, Thiago Macieira wrote:
>>> On Thursday 29 October 2015 21:49:40 Igor Mironchik wrote:
>>>> On 29.10.2015 06:51, Thiago Macieira wrote:
>>>>> On Thursday 29 October 2015 05:51:36 Igor Mironchik wrote:
>>>>>> P.S. Why QTextStream doesn't have something like get(), peek(),
>>>>>> unget(),
>>>>>> putback()?
>>>>> Explain what you would want those functions to do.
>>>> The same like in std::istream, for example...
>>> The iostreams are, in my opinion, the worst part of the Standard Library.
>>> I
>>> don't consider them a good implementation, even if they have good ideas
>>> (<<
>>> and >>).
>>>
>>> istream                 QTextStream
>>> get                             read and readLine
>>
>> Agree, read(), readLine(), and overloaded >> are completely cover get()
>> usage.
>>
>>>          the overload with a delimiter: there was a discussion about
>>> replacing
>>>          readLine with that, but it hasn't happened
>>> peek                    <missing, no one has ever asked for it>
>>
>> It can be useful in some cases, for example, when you implementing some sort
>> of parsers where very often you need to know what next character is but
>> don't really need to seek stream's position.
>>
>>> unget                   seek(pos() - 1) (slow! can't be avoided)
>>
>> 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).

Ok, you read chars (bytes) and you unget() bytes. What is the problem? 
With QTextStream you read QChar but can't seek to one QChar back.

The main reason why I use QTextStream and not std::wistream, for 
example, that QTextStream can automatically detect encoding and can 
tune. And I don't have any pain with reading text files. I don't need to 
worry about encoding of text files. But it can be a big problem with 
std::istream...

-- 
Best Regards,
Igor Mironchik.




More information about the Interest mailing list