QString转字符串的乱码:
先在头文件加入:
//解决QString到char的中文乱码 #if _MSC_VER >= 1600 #pragma execution_character_set("utf-8") #endif
然后在cpp文件中:
char* sendmid; //生成特定格式的帧 QString str = QString("2|%1|%2").arg(ui.name->text()).arg(ui.user_content->toPlainText()); QByteArray ba = str.toLocal8Bit(); sendmid = ba.data();
字符串到QString乱码:
QString str = QString::fromLocal8Bit(friend_mid);//就这么简单