Qt5中文乱码及qDebug

Qt5中文乱码及qDebug,第1张

//QT默认为UTF-8编码
int main(int argc, char *argv[])
{
//在Qt程序中出现latin1字符集以外的字符集,我们会立刻马上想到QTextCodec。


QTextCodec *codec = QTextCodec::codecForName("UTF-8"); QTextCodec::setCodecForLocale(codec);

QApplication a(argc, argv);    

QString Str="8中文";
QTextCodec *mTextCodec = QTextCodec::codecForName("GBK");
qDebug() << mTextCodec->toUnicode(Str.toUtf8()).toStdString().c_str(); 
qDebug() << mTextCodec->toUnicode("8中文").toStdString().c_str();
MainWindow w;   
a.setQuitOnLastWindowClosed(true);    
w.setWindowState(Qt::WindowMaximized);     
w.show();   
return a.exec();
}
					
										


					

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/568038.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-04-09
下一篇 2022-04-09

发表评论

登录后才能评论

评论列表(0条)

保存