Results 1 to 5 of 5

Thread: Character by Character (Unicode?) File Reading

  1. #1
    Join Date
    Aug 2006
    Location
    Madison, WI USA
    Posts
    153
    Thanks
    35
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Question Character by Character (Unicode?) File Reading

    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?

  2. #2
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Character by Character (Unicode?) File Reading

    May be QChar::unicode might help you

  3. #3
    Join Date
    Aug 2006
    Location
    Madison, WI USA
    Posts
    153
    Thanks
    35
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Character by Character (Unicode?) File Reading

    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.

  4. #4
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Character by Character (Unicode?) File Reading

    Have a look at QTextStream. There you can set the codec and get a single character via QTextStream::read( qint64 maxlen ).

  5. The following user says thank you to Lykurg for this useful post:

    mclark (22nd April 2009)

  6. #5
    Join Date
    Aug 2006
    Location
    Madison, WI USA
    Posts
    153
    Thanks
    35
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Character by Character (Unicode?) File Reading

    Thanks people!

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

Similar Threads

  1. Progress of reading the file
    By ModeZt in forum Newbie
    Replies: 1
    Last Post: 11th April 2009, 23:36
  2. help in reading XML file
    By cshiva_in in forum Qt Programming
    Replies: 1
    Last Post: 24th March 2008, 13:55
  3. QTextStream loses position while reading file
    By bjh in forum Qt Programming
    Replies: 2
    Last Post: 13th February 2008, 15:47
  4. Replies: 3
    Last Post: 18th October 2007, 18:07
  5. Reading a unicode names from a file???
    By darpan in forum Qt Programming
    Replies: 7
    Last Post: 3rd May 2006, 17:28

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.