QString中汉字是按照UTF-8编码的,QString::toUtf8是输出UTF-8字符集,QString::local8bit是本地操作系统的字符集,QString::tolatin是Ascii码字符集
下图代码中,汉字转成latin
QString tmp="汉字";是无意义的,因为ascii里就没有中文的编码呀,所以会返回3f即问号 qDebug() << "tmp=" << tmp << endl; qDebug() << "toUtf8" << tmp.toUtf8() << endl; //返回utf8编码的一串数字 qDebug() << "toLatin1" << tmp.toLatin1() << endl; //"汉字"不在latin1字符集中,所以结果无意义(为??) char *p = new char[1+strlen(tmp.toLatin1().data())]; strcpy(p, tmp.toLatin1().data()); for (int i=0; p[i] != '\0'; i++) { printf("0x%02x ", p[i]); } printf("\n"); delete p; qDebug() << "toLocal8bit" << tmp.toLocal8Bit() << endl;//
标签:编码,UTF,Qt,字符,字符集,汉字,QString From: https://www.cnblogs.com/huskyWuWuWu/p/16727674.html