1.问题现象
环境:win10 使用Qt5.12 + MSVC2017编译 当tr(“奇数个汉子”)或者tr(“中文与—123其它字符一起显示”) Qt报错:error C2001: newline in constant 添加UTF-8 BOM 之后可以编译但是中文乱码
2.解决方法
2.1 有翻译需求(使用tr)
每一个包含中文字符的文件头部中添加
#if _MSC_VER >= 1600
#pragma execution_character_set("utf-8")
#endif
或者tr中写英文 后续再翻译
2.2 不需要翻译
使用QStringLiteral(“中文”);
3.编码修改
3.1 Qt Creator设置编码
建议在creator中修改默认编码,方便 
3.2 Qt Creator右键add UTF-8 BOM无效
使用别的编辑软件(文本编辑器),如Notepad++,打开文件修改编码 
4.参考链接
- https://blog.csdn.net/aiyaya333/article/details/107310775 – QT报错解决:error C2001: newline in constant
- https://blog.csdn.net/seamanj/article/details/70165273 – 关于QT中奇数个汉字出现newline in constant的错误
|