UTF-8 Code error
I'm building an app for spanish language and I have some trouble reading a txt file one i have some characters like á,é,í,ó,ú, Á, É,Í,Ó,Ú, Ñ....
my code is this one:
file.open(QIODevice::ReadOnly | QIODevice::Text);
in.setCodec("UTF-8"); // change the file codec to UTF-8.
QString line = in.readLine();
qDebug() << line.toLocal8Bit(); // convert to locale multi-byte string
with this example, when in the pace of any some character exposed above, i get this one: �
after that, I create some new file with this content: áááááéééÁÁÁÁÁÁÑÑÑÑññññññ
and the code work fine.. I'm thinking that the first file is not coded in UTF-8...
so, what can I do to get the correct characters from my first file ???
I'm using Archlinux, Qt5.2.1, my OS language is English and my locale command give me this output:
Since you think your first file is not UTF-8 encoded, then check that in order to be sure and then figure out which is the used encoding.
Or since your locale settings are using UTF-8, just convert your first file into UTF-8, for instance using the "C-x C-m f" in emacs. If this file was obtained by copy-paste from a web page or from a pdf, it might contain special characters which prevent the UTF-8 encoding to be used.