c++ - Converting QString from string in a file -


i want set text in qlabel need use qstring. read file , text contains accents. tried qstring::fromutf8() doesn't work.

any idea?

string line; qstring linetranslate; getline(file, line); linetranslate = qstring::fromstdstring(line); m_nomcourant->settext(qstring::fromlatin1("<u><strong>nom courant :</strong></u> ") + linetranslate); 

desired output:

nom courant : requin nom scientifique : carcharhinus menalopterus  habitat : côtier / dans les zones coralliennes jusqu'à -30m famille : carcharhinidés 

actual output:

nom courant : requin nom scientifique : carcharhinus menalopterus  habitat : c?tier / dans les zones coralliennes jusqu'? -30m famille : carcharhinid?s 

edit: advise me use have qstring several lines?

you need know encoding (charset) used in file. either use fromutf8, or else - using qtextcodec.

example qt docs:

qtextcodec *codec = qtextcodec::codecforname("shift-jis"); qtextdecoder *decoder = codec->makedecoder();  qstring string; while (new_data_available()) {     qbytearray chunk = get_new_data();     string += decoder->tounicode(chunk); } delete decoder;