Results 1 to 2 of 2

Thread: reading ANSI ( Windows-1252) file with Cyrillic content and to encode it to UTF 8

  1. #1
    Join Date
    Mar 2011
    Posts
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default reading ANSI ( Windows-1252) file with Cyrillic content and to encode it to UTF 8

    Hello to everyone,
    I've got one problem.

    I read one text file that is encoded with ANSI (i.e Windows-1252). The important thing is that the file has Cyrillic content. Because of that the Cyrillic part of the text i get it as question marks (?????).
    I want to encode the content with utf8 encoding, in order to get the Cyrillic text back to normal before I put the content into database.

    I use QFile to open the file and QTextStream to read the file content

    Any suggestions?

    Best Regards,
    Bastrijan

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: reading ANSI ( Windows-1252) file with Cyrillic content and to encode it to UTF 8

    Code Page 1252 is the standard Windows western European code page. I think you want 1251 for Cyrillic.

    You should call QTextStream::setCodec() with a QTextCodec generated with QTextCodec::codecForName("windows-1251") (or "CP1251")

    Have a look at the Codecs example
    Last edited by ChrisW67; 22nd May 2012 at 01:35.

Similar Threads

  1. QMake Reading content from a file in qmake
    By MarcoAlanen in forum Qt Tools
    Replies: 2
    Last Post: 27th August 2014, 07:47
  2. Cyrillic support
    By tehman in forum Newbie
    Replies: 2
    Last Post: 7th February 2012, 13:15
  3. QWebView Reading content shown by Javascript
    By lhg in forum Qt Programming
    Replies: 0
    Last Post: 14th October 2011, 19:00
  4. Replies: 11
    Last Post: 10th February 2011, 00:38
  5. Problems reading content of QFile
    By martinn in forum Newbie
    Replies: 12
    Last Post: 6th April 2010, 18:42

Tags for this Thread

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.