请问如何将UTF-8的char *字符串转换为gb2312的char *啊?还有如何将gb2312的char *转换为UTF-8的char *啊?请问QT上有相关的库函数吗?
------解决方案--------------------
我做过linux下读GBK编码的文件,然后转UTF8的程序
主要的代码就是下面的
- C/C++ code
QFile file_w(DATA_PATH + QString("helperweb.html")); file_w.open(QIODevice::WriteOnly | QIODevice::Text); QTextCodec *codec = QTextCodec::codecForName("GBK"); QTextStream ts(&file_w); ts<<codec->toUnicode(reply->readAll())<<endl; file_w.close();
------解决方案--------------------
QByteArray QString::toUtf8 () const
Returns a UTF-8 representation of the string as a QByteArray.
UTF-8 is a Unicode codec and can represent all characters in a Unicode string like QString.
However, in the Unicode range, there are certain codepoints that are not considered characters. The Unicode standard reserves the last two codepoints in each Unicode Plane (U+FFFE, U+FFFF, U+1FFFE, U+1FFFF, U+2FFFE, etc.), as well as 16 codepoints in the range U+FDD0..U+FDDF, inclusive, as non-characters. If any of those appear in the string, they may be discarded and will not appear in the UTF-8 representation, or they may be replaced by one or more replacement characters.
See also fromUtf8(), toAscii(), toLatin1(), toLocal8Bit(), and QTextCodec.
就是把数据读取到 Qstring里面 然后调用toUtf8 就可以转换成UTF-8的了……