why readline result weird character?
Dear my friends... I am making an application with Qt and SuSE 9.1. I want to read the content of file "otentik.txt", like this : QString lines, line; QFile file; file.flush(); QDir::setCurrent( "/localhome/patrixlinux/arsip/proyek/qt/kvclient" ); file.setName( "otentik.txt" ); file.open(IO_ReadWrite); int i = 0; QTextStream str(&file); line = file.readLine(lines, 50); lines = QString::fromLatin1(line); double gede = sizeof(file); QString cetak = QString("file otentik %1 = %1 . gedenya =%1") .arg( QString::number(i++) ) .arg( lines.latin1() ) .arg( QString::number(gede) ); statusBar()->message(cetak, 300000); printf(cetak); file.close(); I wrote one line into the file like this: QString taro = QString("%1;%1;") .arg(un) .arg(pw); f.writeBlock( taro, qstrlen(taro) ); compilation no error. But the reading result only "y" with a weird wave sign on the top of the "y". Why is it so? Please tell me. __________________________________ Do you Yahoo!? Yahoo! Mail Address AutoComplete - You start. We finish. http://promotions.yahoo.com/new_mail
On Friday 08 October 2004 18:53, Prabu Subroto wrote:
QString lines, line; QFile file; file.flush(); QDir::setCurrent( "/localhome/patrixlinux/arsip/proyek/qt/kvclient" ); file.setName( "otentik.txt" ); file.open(IO_ReadWrite); int i = 0; QTextStream str(&file); line = file.readLine(lines, 50); lines = QString::fromLatin1(line);
^^^^^^^^^^^^^^^^ This is a bad idea. You silently assume that every text you read is encoded in Latin1 - which may or may not be appropriate. You should rather use the current locale settings. On a SuSE Linux system, UTF-8 is the default locale - but of course the user can override that. So you should rather check the LANG and LC_CTYPE environment variables and use the appropriate encoding conversion - like QString::fromLocal8Bit() or QString::fromUtf8(). Maybe even QTextCodec::codecForLocale() can figure that out more easily - altough I have to admit I never used that one. For more details, see http://doc.trolltech.com/3.3/qstring.html#fromLocal8Bit http://doc.trolltech.com/3.3/qstring.html#fromUtf8 http://doc.trolltech.com/3.3/qtextcodec.html#codecForLocale CU -- Stefan Hundhammer <sh@suse.de> Penguin by conviction. YaST2 Development SuSE Linux AG Nuernberg, Germany
participants (2)
-
Prabu Subroto
-
Stefan Hundhammer