Results 1 to 2 of 2

Thread: Qfile and QTextStream

  1. #1
    Join Date
    Feb 2006
    Posts
    60
    Thanks
    21
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Qfile and QTextStream

    hi,
    whats the advantage of using QTextStream over QFile? i.e i convert to QTextStream (e.g QTextStream in(&file)) and reading the lines, instead of using the Qfile readLine method.

    I use QT4.1.3

    Thank you,

    regards,
    sreedhar
    Last edited by sreedhar; 28th June 2006 at 11:36. Reason: mentioning the version of QT

  2. #2
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Qfile and QTextStream

    Quote Originally Posted by sreedhar
    hi,
    whats the advantage of using QTextStream over QFile? i.e i convert to QTextStream (e.g QTextStream in(&file)) and reading the lines, instead of using the Qfile readLine method.
    regards,
    sreedhar
    The advantage is the codec ... if you like save file to utf8
    QTextCodec *codecutf8 = QTextCodec::codecForMib(106);
    or latin
    QTextCodec *codeclatin1 = QTextCodec::codecForMib(4);

    QTextStream in(&data);
    in.setAutoDetectUnicode(false);
    in.setCodec(codecutf8);


    default go all to latin iso depend on os config....
    if you save xml file and other apps like this file on utf8

    to read a a utf8 file qt cann not autodetect tahs file is utf8 and destroy the file dual utf8 convert!

    to read file ..... if a utf8

    if (file.open(QFile::ReadOnly | QFile::Text)) {
    inside = QString::fromUtf8(file.readAll());
    file.close();
    }

  3. The following user says thank you to patrik08 for this useful post:

    sreedhar (29th January 2007)

Similar Threads

  1. QSettings vs (QFile + Qtextstream)
    By nupul in forum Newbie
    Replies: 5
    Last Post: 10th April 2006, 08:26
  2. segfault on qtextstream
    By patcito in forum Qt Programming
    Replies: 13
    Last Post: 26th February 2006, 14:10
  3. qtextstream & qstring
    By mickey in forum Newbie
    Replies: 3
    Last Post: 24th February 2006, 20:18

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.