Qt中UTF-8转Unicode
来源:互联网 发布:江苏高考知乎 编辑:程序博客网 时间:2024/06/04 20:43
#include <QtCore/QCoreApplication>#include <QDebug>#include <iostream>#include <QTextCodec>int main(int argc, char *argv[]){ QCoreApplication a(argc, argv); // const std::string str = "汉字"; const QString str = "汉字"; std::cout << str.length() << std::endl; QTextCodec *codec = QTextCodec::codecForName("UTF-8"); QString unicode_str = codec->toUnicode(str.toLatin1().data()); for(int i = 0;i <unicode_str.length();++i) { qDebug() << QString::number(unicode_str[i].unicode(),16); } return a.exec();}
注意点了
1.
QTextCodec *codec = QTextCodec::codecForName("UTF-8");
这个的选择要和你系统的编码相对应,我的系统编码方案是UTF-8,所以长度为6,因为一个UTF-8的字符使用3个字节来表示,不然就会出错。还有就是对于QString
使用str.toLatin1().data()如果是std::string直接使用str.data()就可以了
- Qt中UTF-8转Unicode
- Qt中unicode转utf-8
- UTF-8 转 Unicode
- UTF-8 转 Unicode
- Unicode转UTF-8
- unicode转utf-8
- Unicode转utf-8
- Unicode转UTF-8
- UTF-8 转 UNIcode
- php unicode转utf-8
- ios Unicode 转 UTF-8
- unicode 转 utf-8编码
- iOS unicode转utf-8
- 汉字utf-8转unicode
- VC中Unicode字符集转UTF-8字符集
- C++中 Unicode 与 UTF-8 编码互转
- python中 encode,decode,unicode,utf-8
- python中编码unicode和utf-8
- 编程面试的10大算法概念汇总
- 通过交换相邻数来完成排序所需要的最少交换次数
- C#调用C++编译生成的dll文件
- 视觉直观感受 7 种常用的排序算法
- 6大细节证明 你其实没那么聪明
- Qt中UTF-8转Unicode
- javabean总结
- 编程面试的10大算法概念汇总
- 关于创业
- Google推荐的15条军规:HTML5代码规范
- android 设备虚拟菜单键不显示
- 统计字符串中(大/小写)字母个数
- object c 图书管理系统
- 9duoj1014