我正在使用 QTextBrowser 显示与应用程序位于同一目录中的外部 html 文档(及其图像资源)。相对路径根本不起作用,如果我输入图像的绝对文件路径,它显示正常,但在加载 html 文档之前会出现警告。警告说 "QFSEngine::open: No file specified" 。我正在使用这个片段加载我的 html 文件:
QFile file(QApplication::applicationDirPath().append("/test.html"));
if(!file.open(QIODevice::ReadWrite|QIODevice::Text))
return;
QTextStream in(&file);
ui->textBrowser->setHtml(in.readAll());
file.close();
这是我的 html 文件:
<!doctype html>
<html>
<img src="test.png">
<p>paragraph which contains some text</p>
</html>
我在阅读 html 时出错了,还是我必须在我的 cpp 文件中包含任何内容?