GB编码与UTF8编码的转换【转载】

在主函数app后加上这句:


QTextCodec::setCodecForLocale(QTextCodec::codecForName("GB18030"));



然后是从UTF8编码到GB编码的字符串转换方法:



QString Utf8_To_GB(QString strText)
{
    return QString::fromUtf8(strText.toLocal8Bit().data());
}



至于从GB到UTF8,那大家就经常用了:


QString GB_To_Utf8(char *strText)
{
    return QString::fromLocal8Bit(strText);
}

原地址:http://www.qtcn.org/bbs/read-htm-tid-2540-fpage-410.html

猜你喜欢

转载自www.cnblogs.com/Hellscythe/p/9220896.html