我正在使用 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 文件中必须包含任何内容?
最佳答案
您需要调用QTextBrowser::setSearchPaths
包含您的 .html 的完整路径。
关于html - 显示图像的文本浏览器显示 "QFSEngine::open: No file specified "警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25841852/