序言
老实说,这篇内容网上一抓一大把,但是我不写又好像我不会似的,老是有人来质疑我会不会,所以我来重复下
一、转换三步
正常转换其实就三步,两定义,一转换
QTextCodec *gbk = QTextCodec::codecForName( "GB18030" );
QTextCodec *utf8 = QTextCodec::codecForName( "UTF-8" );
QString data = utf8->fromUnicode( gbk->toUnicode( QBytearray ) );
二、可转换编码一览
虽说是这么说,但是实际可转换的编码要根据Qt助手TextCodec里面查看
Qt5.12可转换编码一览
Big5
Big5-HKSCS
CP949
EUC-JP
EUC-KR
GB18030
HP-ROMAN8
IBM 850
IBM 866
IBM 874
ISO 2022-JP
ISO 8859-1 to 10
ISO 8859-13 to 16
Iscii-Bng, Dev, Gjr, Knd, Mlm, Ori, Pnj, Tlg, and Tml
KOI8-R
KOI8-U
Macintosh
Shift-JIS
TIS-620
TSCII
UTF-8
UTF-16
UTF-16BE
UTF-16LE
UTF-32
UTF-32BE
UTF-32LE
Windows-1250 to 1258