[SOLVED] QTextStream don't likes umlauts
I try to write into a csv-file, which works perfectly for normal characters but it doesn't work with german umlauts. setCodec("UTF-8") worked for importing csv-files, seems to not fit here.
Here is the code I using
QString filename = QFileDialog::getSaveFileName(0, "DialogTitle", "filename.csv", "CSV files (.csv);;Zip files (.zip, *.7z)", 0, 0);
if(data.open(QFile::WriteOnly |QFile::Truncate |QFile::))
output << "ßäÄÖöÜü";
maybe someone of you could give me a hint. :)
Thanks in advance
setCodec sets encoding of the stream, not the input data. You pass your string as a const char* string literal which is "assumed to be Latin-1 encoded":http://qt-project.org/doc/qt-5/qtextstream.html#operator-lt-lt-16.
You need to tell it what encoding it is really in.
@output << QString::fromUtf8("ßäÄÖöÜü");
output << QString("ßäÄÖöÜü"); //this ctor assumes utf-8@
In any case it's a bad idea to put national characters in source code.
Later it shouldn't really be in the code, It's just for testing. It's the input from the form which should take umlauts (streets in germany are called Straße; and so on...)
I wasn't precise enough...my code snippet is only for testing and if I take the form input your solution will not work, wouldn't it?
Edit: Problem solved