PDA

View Full Version : Qfile and QTextStream



sreedhar
28th June 2006, 10:36
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

patrik08
28th June 2006, 10:43
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();
}