[Solved] Read special characters from a csv-file
-
Hi
I've got a problem with reading content from a file. And since I can't find any decent solution on the interwebs, I though I asked it here.
My file contains special characters like Š. But when I do a readLine() on my file it returns something strange.
In the file: 'Roman';'Šebrle'
In my QString line: 'Roman';'ebrle'
And when I want to insert it in my database: UPDATE athletes SET lastname = '?ebrle', middlename = '', firstname = 'Roman'...So can anyone help me with this? How to get that Š?
Thanks in advance!
-
When using the QFile.readLine you will store data in a char buffer. This is a 8 bits variable only capable of holding ASCII values. The special characters are available when using the QTextStream to read/write data to the file.
With the QTextCodec class you are able to transform into all kind of character sets. Even automatic detection of the best fitted text codec is possible.
So it could be more like this:
@
if (file.open())
{
QTextStream in(file);
QStringList inputStrings;in.setAutoDetectUnicode (true);
while (!in.atEnd())
{
in >> inputStrings.append();
}
}
@
Don't have my Qt with me, so no idea if the in>>inputStrings.append() will work!
Good luck with the coding! -
Read the Qt documentation:
http://qt-project.org/doc/qt-4.8/qtextstream.html#readLineWhat do you mean with "look for spaces myself"?
@QStringList spaceSeparatedStrings = singleString.split(" ");@
?