Okay, I have a Qt executable in the same directory as a file logo.png
.
I call the following:
QString msg("<html><body><img src='logo.png' /></body></html>");
webView->setHtml(msg);
where webview
is the QWebKit
pointer
However, when I execute the program, the image does not display. I am executing the program from the directory that the image is in... why won't it display? This is driving me nuts!
The logo.png may not be resolved properly if a appropriate baseUrl is not given.
Here is an example. Note that the application must be run from the directory containing logo.png, but the dummy.html need not exist. It is just used to provide a proper baseUrl.
#include <QtCore>
#include <QtGui>
#include <QtWebKit>
int main(int argc, char * argv[])
{
QApplication app(argc, argv);
QUrl baseUrl = QUrl::fromLocalFile(QDir::current().absoluteFilePath("dummy.html"));
QString msg("<html><body><img src='logo.png' /></body></html>");
QWebView *webView = new QWebView;
webView->setHtml(msg, baseUrl);
webView->show();
return app.exec();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With