为什么qt webkit无法加载本地图像?

时间:2013-02-17 01:42:17

标签: qt webkit

我正在将一个html文件加载到QWebView:

<img src="/home/xxx/.config/xxx/chat_img/test.png" />
<img src="test.png" />
<img src="file://test.png" />

但没有显示任何内容。如果我用在线图像(外部源)替换图像src,例如http://domain.com/file.png然后显示它。所以我想知道的是为什么QWebView没有加载我的本地文件? 感谢。

1 个答案:

答案 0 :(得分:0)

我无法重现你的问题。我尝试用这种方式创建一个QWebView:

#include <QApplication>
#include <QWebView>
#include <QWebFrame>

int main(int argc, char *argv[])
{
    QApplication app(argc, argv);
    QWebView view;
    view.page()->mainFrame()->load(QUrl::fromLocalFile(html_file));
    view.show();
    return app.exec();
}

绝对路径或uri(你错过了斜线)都在工作:

<img src="/abs/path/to/image.jpg" />
<img src="file:///abs/path/to/image.jpg" />
相关问题