Results 1 to 6 of 6

Thread: QIODevice and QTextCodec?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    May 2006
    Posts
    108
    Thanks
    35
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Question QIODevice and QTextCodec?

    Hi,

    i read files like this,

    Qt Code:
    1. string entire;
    2. char buf[1024];
    3. while (device->readLine(buf, sizeof(buf)) && !device->atEnd()) { //QIODevice = device
    4. entire += buf;
    5. //...
    6. }
    7. size_t length = entire.length();
    8.  
    9. for (size_t i = 0; i < length; ++i) {
    10. char c = entire[i];
    11. //...
    12. s.append(c);
    13. }
    To copy to clipboard, switch view to plain text mode 

    but my QSting ("s") looks dirty. The problem is the file can be coded in utf8, iso 8859-15 and a lot more.

    How can i read the file with the right codec, if the user choose the codec before?

    I have try QTextCodec::setCodecForCStrings( QTextCodec::codecForName( codec ) ) but i hink thats not right. Can you help me pleas?
    Last edited by whitefurrows; 25th November 2010 at 20:36.

Similar Threads

  1. Replies: 0
    Last Post: 23rd December 2009, 13:53
  2. QTextCodec bad encoding?
    By ComaWhite in forum Newbie
    Replies: 0
    Last Post: 18th September 2009, 06:15
  3. Question in QTextCodec.
    By morgana in forum Newbie
    Replies: 1
    Last Post: 21st September 2008, 16:29
  4. QTextCodec: using KOI8-R, probe failed (e0 ce ru)
    By hvengel in forum Qt Programming
    Replies: 0
    Last Post: 4th October 2007, 21:35
  5. QTextCodec::setCodecForCStrings() in libraries
    By conexion2000 in forum Qt Programming
    Replies: 5
    Last Post: 10th August 2007, 21:21

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
  •  
Qt is a trademark of The Qt Company.