qt creator 中文乱码

SuperCoderJz 2016-12-16 08:44:54
用qt creator写一个连接数据库的程序,版本为qt5.5.0,调用
QTool::showMsg("数据库连接失败");
显示乱码,其中showmsg方法为

int QTool::showMsg(char* strMsg)
{
QString str(strMsg);
ShwMsgDlg *msgDlg = new ShwMsgDlg();
msgDlg->setShowText(str);
int ret = msgDlg->exec();
delete msgDlg;
msgDlg = NULL;
return ret;
}

...全文
670 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
晋晔 2017-01-20
  • 打赏
  • 举报
回复
QTextCodec *utf8 = QTextCodec::codecForName("utf-8"); QTextCodec::setCodecForLocale(utf8); 加上这些话
Coutel 2017-01-20
  • 打赏
  • 举报
回复
活用 QString QString::fromLocal8Bit ( const char * str, int size = -1 ) QString QString::fromUtf8 ( const char * str, int size = -1 )。 老版的乱码解决方案好像在新的QT里被废除了。
yh2711524 2017-01-20
  • 打赏
  • 举报
回复
QString NetAccess::textCodecFromGbk(char* str) { QTextCodec *gbk = QTextCodec::codecForName("gbk"); QByteArray encoded = gbk->fromUnicode(QString::fromLocal8Bit(str)); return gbk->toUnicode(encoded); }
诺水城子 2016-12-30
  • 打赏
  • 举报
回复
显示中文需要转码的,我通常用的utf-8
佳朗 2016-12-23
  • 打赏
  • 举报
回复
需要转码,5版本以上不同于之前的版本,那三句话貌似没什么用
孔方发发 2016-12-20
  • 打赏
  • 举报
回复
main函数加入这些代码

    QTextCodec::setCodecForLocale(QTextCodec::codecForName("UTF-8"));    //设置中文显示
    QTextCodec::setCodecForTr(QTextCodec::codecForName("UTF-8"));
    QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));
namezdd 2016-12-19
  • 打赏
  • 举报
回复
QString str(strMsg);改成QString str = QString::fromLocal8Bit(strMsg)
ersaijun 2016-12-17
  • 打赏
  • 举报
回复
中文还得加些代码

16,212

社区成员

发帖
与我相关
我的任务
社区描述
Qt 是一个跨平台应用程序框架。通过使用 Qt,您可以一次性开发应用程序和用户界面,然后将其部署到多个桌面和嵌入式操作系统,而无需重复编写源代码。
社区管理员
  • Qt
  • 亭台六七座
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧