QT 字符编码转换
程序员文章站
2022-03-31 14:52:14
...
//String以GBK编码格式转Ascii
inline QByteArray String2Ascii(QString str){
QTextCodec *pCodec = QTextCodec::codecForName( "GBK" );
QByteArray data = pCodec->fromUnicode(str);
return data;
}
//把ascii字符数组以GBK编码格式转QString
inline QString Ascii2String(const char *asciichar,int length)
{
QByteArray dd= QByteArray::fromRawData(asciichar,length);
QString uc=QTextCodec::codecForName("GBK")->toUnicode(dd);
uc.remove(QChar::Null);
return uc;
}
上一篇: 拨开字符编码的迷雾--字符编码转换