QTextEditor 在 QT Ruby 中将引号返回为问号

发布于 2024-07-14 22:43:34 字数 189 浏览 8 评论 0原文

当我从 Word 文档复制并粘贴到 QT TextEditor 中时,看起来看起来不错。 但是,当我尝试使用 toPlainTexttoHTML 访问文本时,它会返回带有所有引号(双引号和单引号)作为问号的文本。 有没有解决的办法? 我正在使用 qt4-qtruby 绑定。

When I copy and paste from a Word document into a QT TextEditor, It seems to look fine. But when I try to access the text using toPlainText or toHTML, it returns the text with all of the quotes (double and single) as question marks. Is there a way around this? I am using the qt4-qtruby bindings.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

寄离 2024-07-21 22:43:34

这是因为 Word 中使用的引号实际上并不是 ASCII 引号字符 - 它们是某种看起来像引号的时髦 unicode 字符。

对于 HTML,如果您使用 UTF-8 编码,它应该可以正常工作。 对于纯文本,你的运气就很差了。

这是一个包含更多信息的好页面

That's because the quotes used in Word aren't actually ASCII quote characters - They are some kind of funky unicode character that kind of looks like a quote.

For HTML, if you use UTF-8 encoding, it should work fine. For plain text though you're pretty much out of luck.

Here's a nice page with some more info

赏烟花じ飞满天 2024-07-21 22:43:34

我假设您正在使用 QTextEdit。 我认为问题与编码有关。 尝试将 Word 文档另存为纯文本并尝试相同的操作。 如果与单词互操作很重要,我认为您必须弄清楚如何更改复制粘贴的编码。

编辑
请发布您最终使用的任何解决方案。 我很感兴趣。

我也是 QT 的新手,这只是我的意见。

我希望这有帮助。

I assume that you are using a QTextEdit. I think the problem is encoding related. Try saving the word document as plain text and trying the same. If it is important to interoperate with word, I think you will have to figure out how to change the encoding on copy-paste.

Edit
Do post whatever solution you use finally. I am very interested.

I am new to QT as well and this is just my opinion.

I hope this helps.

染火枫林 2024-07-21 22:43:34

当您调用 toPlainText() 时,它会返回一个 QStringQString 内部是 unicode,因此只要数据位于 QString 内部就应该没问题。 如果您使用 toAscii()QString 中获取数据,那么这就是发生错误转换的地方。
如果这个理论是正确的,请在 QString 上使用 toUtf8() 而不是 toAscii()

When you're calling toPlainText() it returns a QString. QString is internally unicode so as long as the data is inside the QString it's supposed to be OK. If you get the data out of the QString using toAscii() then that's where the bad conversion takes place.
If this theory is correct, use toUtf8() instead of toAscii() on the QString.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文