QWebView *view = new QWebView();
view->setUrl(QUrl("https://www.example.com"));
view->setUrl(QUrl::fromLocalFile("C:/path/to/file.html"));
QString html = "Hello Qt WebKit!";
view->setHtml(html);
#include
#include
#include
#include
#include
int main(int argc, char *argv[]) {
QApplication app(argc, argv);
QWebView view;
std::ifstream fin("test.html");
std::stringstream buffer;
buffer << fin.rdbuf();
view.setHtml(QString::fromStdString(buffer.str()));
view.show();
return app.exec();
}
Qt WebKit 提供了輕量級 HTML 渲染與 JS 引擎,適合桌面應用內嵌網頁、爬蟲渲染動態頁。環境配置關鍵在於 Qt 版本與 VS 插件匹配,代碼極其簡潔。