网上有很多例子,但是几乎都没有正常显示中文,经过痛苦的试验和折磨,终于解决了QT字符串在osg中的正常显示问题,下面贴出主要代码,分享给大家。 QTextCodec::setCodecForTr(QTextCodec::codecForName("GBK")); QTextCodec* code = QTextCodec::codecForName("UTF-8"); QString qstr = QObject::tr("中国"); string str = code->fromUnicode(qstr).data(); osgText::Text* text = new osgText::Text; textOne->setFont("C:/WINDOWS/Fonts/STSONG.ttf");//设置中文字体 text->setText(str, osgText::String::ENCODING_UTF8);