qt qwebview 用setHtml();传入的html代码,然后显示后里面的图片不能显示,是怎么回事?要怎么解决呢?
1个回答
展开全部
根据文档上描述,显示图片需要setHtml的第二个参数。
void QWebView::setHtml ( const QString & html, const QUrl & baseUrl = QUrl() )
External objects such as stylesheets or images referenced in the HTML document are located relative to baseUrl.
// example
#include<QtCore/QFile>
#include<QtCore/QUrl>
#include<QtGui/QApplication>
#include<QtGui/QMainWindow>
#include<QtWebKit/QWebView>
int main(int argc,char*argv[])
{
QApplication app(argc, argv);
QMainWindow window;
QWebView webview(&window);
QFile source(":/google.com.html");
source.open(QIODevice::ReadOnly);
webview.setHtml(QString::fromUtf8(source.readAll().constData()),QUrl("http://google.com"));
window.setCentralWidget(&webview);
window.show();
return app.exec();
}
参考资料:
http://stackoverflow.com/questions/5126294/qwebview-doesnt-load-any-external-resources-if-it-loads-a-html-file-from-qresou
void QWebView::setHtml ( const QString & html, const QUrl & baseUrl = QUrl() )
External objects such as stylesheets or images referenced in the HTML document are located relative to baseUrl.
// example
#include<QtCore/QFile>
#include<QtCore/QUrl>
#include<QtGui/QApplication>
#include<QtGui/QMainWindow>
#include<QtWebKit/QWebView>
int main(int argc,char*argv[])
{
QApplication app(argc, argv);
QMainWindow window;
QWebView webview(&window);
QFile source(":/google.com.html");
source.open(QIODevice::ReadOnly);
webview.setHtml(QString::fromUtf8(source.readAll().constData()),QUrl("http://google.com"));
window.setCentralWidget(&webview);
window.show();
return app.exec();
}
参考资料:
http://stackoverflow.com/questions/5126294/qwebview-doesnt-load-any-external-resources-if-it-loads-a-html-file-from-qresou
追问
我是传入的html代码。
问题最后解决了,图片要用file:///指明路径才行
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询