How to read UTF-8 text from file using Qt?

See QTextStream::setCodec():

in.setCodec("UTF-8");

I was also having ???? when reading an XML file with QXmlStreamReader. I fixed it by calling this before reading the file:

QTextCodec::setCodecForLocale(QTextCodec::codecForName("UTF-8"));

You shuold do:

QTextStream in(&file);
in.setCodec("UTF-8"); // change the file codec to UTF-8.

while(!in.atEnd())
{
    QString line = in.readLine();
    qDebug() << line.toLocal8Bit(); // convert to locale multi-byte string 
}