Qt:XML流不直接写入字符串
我的问题如下:我的程序处理项目并将其设置保存在 XML 文件中。它还使用相同的 QXmlStreamWriter 类创建可查看的 HTML 文件。然而,由于 XML 应该跳过特定符号,因此许多字符在 HTML 文件中无法正确表示。有没有办法使用 XML 流将任何 QString 直接写入 HTML 文件?像 writeRaw()
函数之类的东西?
因为我找不到这个问题的解决方案,所以我必须创建一个 QTextStream(xml->device()) 并写入流中。然而,该流似乎是异步工作的,并且根据具体情况,有时它仅在 XML 流完成写入整个文件后才写入其部分代码。在 HTML 术语中,这意味着部分代码出现在 标记之后。还有其他解决办法吗?
我将不胜感激任何帮助!
My problem is the following: my program works with projects and saves their settings in an XML file. It also creates viewable HTML files using the same QXmlStreamWriter
class. However, because XML is supposed to skip particular symbols, a lot of characters are not propery represented in the HTML file. Is there a way to write any QString directly into an HTML file using an XML stream? Something like writeRaw()
function?
Because I could not find solution to this problem, I had to create a QTextStream(xml->device())
and write into the stream. However, the stream seems to work assynchronously and, dpeending on the situation, sometimes it writes its part of code only after XML stream has finished writing the whole file. In HTML terms, it means, that a part of the code appears after </html>
tag. Is there any other solution?
I would be grateful for any help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好的,我解决了我的问题。
在文档中,它说 QString::QString(QByteArray&) 使用
QString::fromAscii()
函数将字节数组转换为强函数。我用 QString::fromUtf8(myByteArray) 替换了这部分,它成功了!Okay, I solved my issue.
In the documentaion it says that
QString::QString(QByteArray&)
converts a byte array to a strong usingQString::fromAscii()
function. I replaced this part withQString::fromUtf8(myByteArray)
, and it worked!