// 设置中文字体编码
#if (QT_VERSION < QT_VERSION_CHECK(5,0,0))
QTextCodec *codec = QTextCodec::codecForName("UTF-8")
QTextCodec::setCodecForLocale(codec)
QTextCodec::setCodecForCStrings(codec)
QTextCodec::setCodecForTr(codec)
#else
QTextCodec::setCodecForLocale(QTextCodec::codecForName("UTF8"))
#endif
// 然后再进行字符传输
qt fromLocal8Bit()函数可以设置编码。QT默认的编码(unicode)是不能显示中文的,可能由于windows的默认编码的问题,windows默认使用(GBK/GB2312/GB18030),所以需要来更改QT程序的编码来解决中文显示的问题。
系统直接自动将char *的参数转换成为系统默认的编码,然后返回一个QString。
#include <QApplication>
#include <QTextCodec>
#include <QLabel>
int main(int argc,char *argv[])
{
QApplication app(argc,argv)
QString str
str = str.fromLocal8Bit("Qt中文显示")
hello.setWindowTitle(str)
hello.show()
return app.exec()
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)