?1. Qt4中使用webkit模塊;
? 2. Qt5 ~Qt5.5使用webkitwidgets模塊,使用WebKit作為后端;
? 3. Qt5.6以上版本使用webenginewidgets模塊,使用Chromium作為后端。QT5.6之后開始支持
這里一定要指定msvc2017(或者msvc2019都可以)?64編譯器,如果指定minGW依然會報錯,因為MinGW不支持QWebEngine,如果QT中msvc2019編譯kit是感嘆號說明沒有安裝MSVC2019依賴,
需要在安裝VS2019的時候,把這些也安裝了,我只安裝了X64緩解庫和生成工具,就自動OK了
QT5.15.2 webenginewidgets 64位可以在win7 64位上運行,打包的時候添加vcruntime140_1.dll
QT C++調(diào)用JS
測試的html demo
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title>test1</title>
<script type="text/javascript">
function getGeoData()
{
alert("123");
return "xiaoli"
}
function showalert(text)
{
alert(text)
}
function buttonClick(){
console.log("you click 你點擊了按鈕哦");
res = getGeoData()
document.getElementById('myvalue').innerHTML = res;;
alert(res);
}
function callFunctionDemo(name){
alert("Hello World " + name);
}
</script>
</head>
<body>
<input id="button" type="button" value="點擊" onclick="buttonClick();">
<a id= "myvalue">empty value</a>
</body>
</html>
?創(chuàng)建一個對話框APP,添加
QT ? ? ? += core gui webenginewidgets network
QWebEngineView* m_pWebView;文章來源:http://www.zghlxwxcb.cn/news/detail-815566.html
m_pWebView = new QWebEngineView(this);
this->setCentralWidget(m_pWebView);
this->setWindowState(Qt::WindowMaximized);
m_pWebView->setUrl(QUrl("file:E://web//index.html"));
connect(m_pWebView, SIGNAL(loadFinished(bool)), this, SLOT(slotLoadfinish(bool)));
m_pWebView->show();
//調(diào)用的函數(shù)哪怕沒有參數(shù)也要括號
QString jsCode = QString("showalert('%1')").arg("Hello QtWebEngine xiaoyu```````````!");
m_pWebView->page()->runJavaScript(jsCode, [](const QVariant &v) { qDebug() << v.toString(); });文章來源地址http://www.zghlxwxcb.cn/news/detail-815566.html
到了這里,關(guān)于QT 瀏覽器組件使用的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!