Question

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.

Was it helpful?

Solution

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

OTHER TIPS

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.

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top