我遇到了一个问题,使用QWebChannel从JavaScript访问对象。我目前正在使用Qt5.4.2。qt.webChannelTransport在QWebEngineView中未定义
这里是我的CPP代码:
myObject::myObject(QWidget *parent)
: QMainWindow(parent)
{
QWebEngineView* m_pView = new QWebEngineView(this);
QWebChannel channel;
channel.registerObject(QString("myObject"), this);
m_pView->load(QUrl("file:///D:/index.html"));
setCentralWidget(m_pView);
}
在我的index.html,我包括qwebchannel.js
:
<script type="text/javascript" src="qrc:///qtwebchannel/qwebchannel.js"></script>
而在我的JavaScript文件,我想找回我的对象像这个:
new QWebChannel(qt.webChannelTransport, function(channel) {
var myObject = channel.objects.myObject;
});
但是,我收到以下错误控制台:
Error: qt is not defined
我也试图与navigator.qtWebChannelTransport
来取代它,但我得到:
Error: transport is not defined
有人能告诉我,我做了什么错?谢谢。
编辑:qt.webChannelTransport是否只能用Qt5.5访问?当我阅读QWebEnginePage::setWebChannel
的文档时似乎是这种情况...
这不是一个很好的答案。添加更多信息或示例。这更多的是评论。 –