最經在研究AT指令接受短信,短信是unicode編碼,接受後須要根據系統的編碼方案進行相關的轉碼
好比接受到了一串字符4F60597D,它是「你好」的unicode編碼,一個unicode編碼佔兩個字節,全部能夠使用4個16進制數表示:4F60->你,597D->好。那咱們怎麼轉換了?
在QString中存放的是QChar,你能夠把她看成ushort來看待。由於Qt自己的編碼方案就是unicode。app
QTextCodec *codec = QTextCodec::codecForName("utf-8"); QString str = "0891683108500145F1240D91685143256178F0000831214281659423044F60597D"; QString t = str.mid(58); QStringList s; for(int i = 0;i < t.length();i += 4) { s.append(t.mid(i,4)); } QString t1; foreach (const QString &t, s) { t1.append(t.toUShort(0,16)); } QString re = codec->fromUnicode(t1); qDebug() << QObject::trUtf8(re.toLatin1().data());
先將要處理的字符串按4個一段分割而後轉化成ushort也就是QChar而後拼成一個QString,其實兩步能夠化成一步作。編碼
參考:http://blog.csdn.net/zhx6044/article/details/17656989spa