我正在阅读一个html文件。该文件基本上包含Unicode文本,如下所示:
<b>akko- sati (ā + kruś), akkhāti (ā + khyā), abbahati (ā + bṛh)</b>
但是QTextBrowser没有解释Unicode字体。所以QTextBrowser显示它们如下:
akko- sati (Ä + kruÅ›), akkhÄti (Ä + khyÄ), abbahati (Ä + bá¹›h)
QTextBrowser正确解释了html标签。但是Unicode有什么问题字体有什么问题呢?
以下是我用于读取和填充 Unicode 内容的代码:
void MainWindow::populateTextBrowser(const QModelIndex &index)
{
QFile file("Data\\" + index.data().toString() + ".html");
if (!file.open(QFile::ReadOnly | QFile::Text)) {
statusBar()->showMessage("Cannot open file: " + file.fileName());
}
QTextStream textStream1(&file);
QString string = "<meta http-equiv='Content-Type' content='text/html; charset=utf-8' /><link rel='stylesheet' type='text/css' href='Data/Accessories/qss.css' />";
string += textStream1.readAll();
ui->textBrowser->setHtml(string);
}
但是,如果我不从html文件中读取Unicode内容,而是直接将它们输入到参数中,那么它只会解释Unicode字体。例如,如果我这样做很好:
ui->textBrowser->setHtml("<b>akko- sati (ā + kruś), akkhāti (ā + khyā), abbahati (ā + bṛh)</b>");
如何从html文件中读取Unicode内容并在QTextBrowser中显示它们?
如果有人向我展示我的代码中的错误部分或告诉我解决问题的更好方法,我将非常感激。