PDA

View Full Version : QString::fromLocal8Bit cannot work on Mac OS X, the QTextCodec has issue



royt
25th October 2012, 19:34
My GUI application use QString::fromLocal8Bit(char *) to deal with local encoding strings. For example, on windows the system local is set to "Chinese (PRC)", on Mac the preferred language in preference setting is "Chinese". Then fromLocal8Bit() can properly work on Windows but fails on Mac. I debug the app and trace into Qt Source, the QString uses QTextCodec to finish encoding transformation. On Mac a global static QTextCodec object is initialized as QIconvCodec, it uses 3rd-party iconv library. When transferring a local encoding string (GB2312 encoding for Chinese) to QString (UTF16), somewhere the function iconv_open("UTF-16LE", "") is called, the first param is desination encoding (UTF16) and the second param is source encoding (empty string means local encoding, I think it should be GB2312 or GBK), however the iconv function cannot work for Chinese string, but only for ASCII or Latin1. Could anyone tell me why this happens?

Thanks in advance.