QT将数据库乱码转中文

1. 问题描述:mysql数据库中数据为乱码,需要使用QT函数将乱码转换为QString中文。

2. 解决步骤:

  1)查询乱码的编码格式:

    ①进入以下网站进行查询(乱码例子为:变电站)

    http://www.mytju.com/classcode/tools/messyCodeRecover.asp

    

    ②查询结果:

    得出该乱码的编码格式为windows-1252。

  2)使用QTextCodec函数将该乱码转换为QString。

3. 测试代码

  QString strstat = (("变电站"));
  QTextCodec *codec = QTextCodec::codecForName("Windows-1252");
  QString strutf8 = codec->fromUnicode(strstat);
  QMessageBox::information(this, "", strutf8);

扫描二维码关注公众号,回复: 6248413 查看本文章

4. 测试结果

  

猜你喜欢

转载自www.cnblogs.com/lizhuo987456/p/10873501.html