I have been struggling with character conversion, please help.

I have a file in Chinese (GB2312), I need to read it and then print it on screen (in linux), I got garbage output on screen such as ��?��. I have tried for hours with different conversion. Nothing works!

Here is the code:

Qt Code:
  1. static QString toUnicode( const QString& str )
  2. {
  3. //return QTextCodec::codecForName( "GB2312" )->toUnicode( str.toLatin1() ).toLocal8Bit(); // <- not working
  4. //return QTextCodec::codecForName( "GB2312" )->toUnicode( str.toLatin1() ).toUtf8(); // <- not working
  5. return QTextCodec::codecForName( "GB2312" )->toUnicode( str.toLatin1() ); // <- not working
  6. }
  7.  
  8. void my_read_func()
  9. {
  10. QSettings settings( filename, QSettings::IniFormat );
  11. settings.setIniCodec( QTextCodec::codecForName( "GB2312" ) );
  12. settings.beginGroup( "xxxx" );
  13. {
  14. foreach( const QString& key, settings.allKeys() ) {
  15. QStringList strList = settings.value( key ).toStringList();
  16.  
  17. qDebug() << key << "=" << strList; // <- garbage out
  18.  
  19. foreach( const QString& str, strList ) {
  20. qDebug() << toUnicode( key ) << "=" << toUnicode( str ); // <- garbage out
  21. }
  22.  
  23. }
  24. }
  25. settings.endGroup();
  26. }
To copy to clipboard, switch view to plain text mode