qt 保存文件为utf8
转载:https://www.cnblogs.com/cppskill/p/7999800.html
1 bool TdrawSvg::Save2File(char* _pcFullFileName) 2 { 3 // http://blog.csdn.net/u011314012/article/details/49861363 4 // https://stackoverflow.com/questions/4780507/create-utf-8-file-in-qt 5 6 QString str = FpOwnerWebView->page()->currentFrame()->toHtml(); 7 //QString unicodeString = "Some Unicode string"; 8 QFile fileOut("C:\\zzz.svg"); 9 //if (!fileOut.open(QIODevice::WriteOnly | QIODevice::Text | QFile::Truncate)) 10 if (! fileOut.open(QFile::WriteOnly | QFile::Truncate)) 11 return false; 12 13 QTextStream streamFileOut(&fileOut); 14 streamFileOut.setCodec("UTF-8"); 15 streamFileOut << str; 16 streamFileOut.flush(); 17 18 // ZC: 查到说,下面的参数是true的话 就是保存成"UTF-8 + BOM",false的话 就是保存成"UTF-8" 19 // 但是,我尝试了一下,都是"UTF-8"... 不知为啥... 20 streamFileOut.setGenerateByteOrderMark(true); 21 22 fileOut.close(); 23 }
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具