Question

Manually hard coding html and image files using setHtml and setContent is tedious. Is there a way to automate this? I don't want the Qt 5.2 application to load external files.

Example:

QString content = "<!DOCTYPE html><html lang=\"en\"><head><meta charset=\"utf-8\"><title>Hello World</title></head><html><body><h1>Hello World</h1></body></html>";
QWebView view;
view.show();
view.setHtml(content,QUrl("index.html"));
Was it helpful?

Solution

You should add your html and image files to a qrc (a Qt resource), and thus compile them into the app. Then you can use QWebView's load method to load the resource like this:

QWebView view;
view.load(QUrl(":/myIndex.html");

You can read more about resources here.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top