PDA

View Full Version : Character by Character (Unicode?) File Reading



mclark
22nd April 2009, 00:11
I am required to read a text file character-by-character (newline characters may be embedded in a line). I am concerned that if the file contains Unicode characters none of the QFile reading methods will handle this. True?

The getChar( char* ) method that gives a char (single byte); unacceptable.
The read( 1 ) method will returns a QByteArray, in my case a QByteArray with a single byte; again unacceptable.

What I need is a way to read a (possible Unicode) character from the file one at a time. Is this something I can do with Qt?

aamer4yu
22nd April 2009, 06:32
May be QChar::unicode might help you :)

mclark
22nd April 2009, 16:17
QChar::unicode() would be useful but only after the file read takes place. I'm looking for something that will do a unicode character file read.

Lykurg
22nd April 2009, 16:25
Have a look at QTextStream. There you can set the codec and get a single character via QTextStream::read( qint64 maxlen ).

mclark
22nd April 2009, 16:28
Thanks people!

It looks like the QTextStream::setAutoDetectUnicode() should do what I need.