html - 显示图像的文本浏览器显示 "QFSEngine::open: No file specified "警告

标签 html qt qtextbrowser

我正在使用 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/

相关文章:

c++ - 如何删除选定的图形项目组?

c++ - QLabel 上的绘图点错误

python - QTextBrowser html链接不可点击

python - QT:如何在点击事件上展开/折叠文本(qtextbrowser,qwebview,...)

qt - 无法让 QT "hello world"工作!

javascript - Form Rise-Input 并在填充 CSS 时重复文本

html - 制作包含搜索栏的导航栏

python - 使用 BeautifulSoup 输出 <br> 而不是 <br/>

javascript - 选中复选框时如何禁用 HTML 必需属性?