I am obtaining the content from a QTextEdit
object by using the following code:
QString text=my_QTextEdit.toPlainText();
What is the encoding that QTextEdit
uses, a what encoding is used in the QString
I get back from the toPlainText()
call?
Thanks.
QTextEdit.toPlainText()
returns a QString
object, which is always a unicode character string (see documentation).
The QString
class provides the functions toLatin1()
, toAscii()
and toUtf8()
, which allow you to convert the string from unicode to an 8-bit string that you can process further. So Qt handles the encoding & decoding of the string for you.
If you want to create a QString instance from a given byte-string, you can use the functions fromAscii()
, fromLatin1()
or fromUtf8()
.
All controls in Qt are enabled for 16-bit characters. That means that content of a QTextEdit
is Unicode (or UTF-32/UCS-4) (see also http://developer.nokia.com/Community/Discussion/showthread.php/215203-how-to-correctly-display-Unicodes-in-QPlainTextEdit).
When getting the content of a QTextEdit
control (via plainText()
), you get back a QString
which contains Unicode.
From there on, you can convert to other format as you like: toUTF8()
, toUCS4()
, ...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With