Why Unicode fonts are not showing properly in the QTextBrowser when Unicode contents are read from an html file?

后端 未结 1 573
天命终不由人
天命终不由人 2021-01-24 13:07

I am reading an html file. The file basically contains Unicode texts as follows:

akko- sati (ā + kruś), akkhāti (ā + k         


        
1条回答
  •  鱼传尺愫
    2021-01-24 13:31

    You read a binary file into QString but do not tell the program, which bytes correspond to which unicode character, i.e. you don't specify the "encoding" aka. "codec".

    To debug your problem, ask QTextStream which codes it uses by default:

    QTextStream textStream1(&file);
    qDebug() << textStream1.codec()->name();
    

    On my Linux system, that is already "UTF-8" but it might be different on your system. To force QTextStream interpreting the input as UTF-8, use QTextStream::setCodec.

    0 讨论(0)
提交回复
热议问题