赞
踩
参考:Qt中向ini文件写中文出现乱码问题_qt ini 中文-CSDN博客
感谢作者!!!
关键:
- mSetting.setIniCodec(QTextCodec::codecForName("UTF-8"));
-
- QString::fromLocal8Bit("中文")
(我用的VS2019+Qt5.6.3)
测试代码:
- QSettings mSetting("1.ini", QSettings::IniFormat);
- mSetting.setIniCodec(QTextCodec::codecForName("UTF-8"));
- mSetting.setValue("student/name", QString::fromLocal8Bit("xiongfei"));
- mSetting.setValue("student/age", QString::fromLocal8Bit("42"));
- mSetting.setValue("student/sex", QString::fromLocal8Bit("男"));
-
- mSetting.setValue("teacher/name", QString::fromLocal8Bit("刘春花"));
- mSetting.setValue("teacher/age", QString::fromLocal8Bit("42"));
- mSetting.setValue("teacher/major", QString::fromLocal8Bit("语文"));
-
- qDebug() << mSetting.value("teacher/major").toString();
可以解决中文乱码问题!!!
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。