Solved QTextEdit does not display german Umlauts (öÖüÜäÄß) after loading a textfile
-
@raspe88 is almost certainly correct. My advice is to stick to utf-8 and when saving enforce the encoding with
QString::toUtf8
, consequently when loading you convert the utf8 stream to string withQString::fromUtf8
. And never dofile.readAll().constData()
, what you do is to leaveQString
guessing what you've given it as raw byte data. Do the reading/writing consistently - if you useQTextStream
to write, then by all means, use it read the file as well. -
@raspe88 Thanks for your hint. Unfortunally, this doesn't work for me on Windows, since I have to use
stream << ui->textEdit_Report->toHtml();
in order to save formatted text. when reloading with
QString contents = file.readAll();
the result is still without umlauts.
-
As I said, you should rather use:
QByteArray data = ui->textEdit_Report->toHtml().toUtf8(); file.write(data);
and for reading:
QString contents = QString::fromUtf8(file.readAll());
-
@raspe88 Here's to illustrade what's happening:
I'll try to change the routines accomplishing to kshegunow and'll be back later. :)
-
@kshegunov said in QTextEdit does not display german Umlauts (öÖüÜäÄß) after loading a textfile:
QString contents = QString::fromUtf8(file.readAll());
PERFECT! This solves my issu. Thanks a lot! :)
-
You're welcome.
Btw, Mrs. Onan is rather plump, isn't she? :D -
@kshegunov Thanks, man. This was the solution. Works like a charm now. I guess I should dive deeper into Qt encoding and file operations ;)
-
@mbergmann-sh said in QTextEdit does not display german Umlauts (öÖüÜäÄß) after loading a textfile:
I guess I should dive deeper into Qt encoding and file operations
Qt's documentation is pretty good, so that's a good place to start.
-
@kshegunov oh yes, she is :D
-
Another thing...
(this, trUtf8("Datei öffnen"), "",
Be careful using anything other than 7-bit ASCII for your source files as not all compilers might support that.