QT之UTF-8和GBK之间的相互转换
#include <QTextCodec>
//UTF-8转GBK
QByteArray LS_Unpack::utf8_To_gbk(QByteArray str){
QTextCodec *utf8 = QTextCodec::codecForName("UTF-8");
QTextCodec* gbk = QTextCodec::codecForName("gbk");
QString strUnicode= utf8->toUnicode(str.data());
return gbk->fromUnicode(strUnicode);
}
//GBK转UTF-8
QByteArray LS_Unpack::gbk_To_utf8(QByteArray str){
QTextCodec *utf8 = QTextCodec::codecForName("utf-8");
QTextCodec* gbk = QTextCodec::codecForName("gbk");
QString strUnicode= gbk->toUnicode(str.data());
return utf8->fromUnicode(strUnicode);
}
如果觉得这篇文章对您有帮助,欢迎点赞、评论、转发、收藏!您的支持是我创作的最大动力!