问题: 代码中增加下行时,报错”*.cpp:31: error: C2001: 常量中有换行符“
mode1->setHeaderData(2, Qt::Horizontal, QVariant(QString("过压保护值")));
原因: 根据Visual C++ Compiler Team员工的解释: The compiler when faced with a source file that does not have a BOM the compiler reads ahead a certain distance into the file to see if it can detect any Unicode characters - it specifically looks for UTF-16 and UTF-16BE - if it doesn’t find either then it assumes that it has MBCS. I suspect that in this case that in this case it falls back to MBCS and this is what is causing the problem. 看见了吧,对于那些没有BOM的文件设计就是这样的。从语气上看,他们编译器小组也不打算修改设计。因此呢,在VC上使用“无签名的UTF-8”编码的文件,你就是在抱着一颗不定时炸弹玩耍。由于你永远都不敢肯定哪些词能经过编译,哪些不能!
若是要硬编码字符串,即使是字符编码转换也不必定能帮不上你。一旦你为此增长了字符编码转换的代码,那么也意味着可移植性下降了。由于这从根本上是编译器决定的。
解决办法: 使用notepad++打开该文件,编码——转为UTF-8-BOM编码。
|