基于QT QWebEnginePage :: setWebChannel()传输对象和Qt:无法从javascript调用共享对象方法/属性我试图制作一个小型演示来测试功能.请参阅下面的基本测试代码.我的问题是:
.pro文件
QT += core gui
QT += network webenginewidgets webchannel widgets
TARGET = hfbTestWebChannel
TEMPLATE = app
SOURCES += hfbTestWebChannel.cpp
RESOURCES += hfbTestWebChannel.qrc
Run Code Online (Sandbox Code Playgroud)
.html文件
<html>
<body>
<script type="text/javascript" src="qrc:///qtwebchannel/qwebchannel.js"></script>
<script type="text/javascript">
var theQtObj;
function buttonA()
{
PrintLog("Button A:init")
if (typeof qt !== "undefined")
{
new QWebChannel(qt.webChannelTransport, function(channel)
{
theQtObj = channel.objects.theQtObj;
PrintLog(" done, now theQtObj=" + theQtObj.toString());
});
}
else
PrintLog("!!!qt undefined!!!" );
}
function buttonB()
{
PrintLog("Button B …Run Code Online (Sandbox Code Playgroud)