PDA

View Full Version : Special characters in strings stored in a QStringList



Sergex
4th September 2013, 10:49
Hello,

I have an application that gets a list of names from a text file and store those names in a QStringList. Afterwards, I use that list to access certain items of a QHash that have the names stored in my QStringList as their keys. The problem I am having is that some of the names might have special characters such as é, à , ù, etc.

So when this is the case I realized that when a name such as "Jérémy" for example, this name gets stored in the QStringList as "J?r?my" so when I want to access the item which has as key "Jérémy", my QHash it doesn't find the item.

How can I make the QStringList store the names with special characters correctly ? When reading from the text file to the QStringList I am doing:



QFile file(name);
file.open(QIODevice::ReadOnly | QIODevice::Text);

QTextStream in(&file);
in.setCodec("UTF-8");

// then in a loop while not at the end of the text file..
QString line = in.readLine();
myStrList.append(line);




Appreciate any help! Thanks.

Lesiok
4th September 2013, 12:07
Are You sure that codec UTF-8 is correct ? Maybe this file is in some 8-bit local codec ?
QStringList have nothing to this problem.

wysota
4th September 2013, 15:45
Does "line" in line #8 contain a correctly decoded string? Please verify the string and not its output to the console using qDebug.