Javascript QWebEngineView中未定义qt.webChannelTransport

Javascript QWebEngineView中未定义qt.webChannelTransport,javascript,c++,qt,qtwebengine,Javascript,C++,Qt,Qtwebengine,我在使用QWebChannel从JavaScript访问对象时遇到问题。我目前正在使用Qt5.4.2 以下是我的CPP代码: myObject::myObject(QWidget *parent) : QMainWindow(parent) { QWebEngineView* m_pView = new QWebEngineView(this); QWebChannel channel; channel.registerObject(QString("myObject

我在使用QWebChannel从JavaScript访问对象时遇到问题。我目前正在使用Qt5.4.2

以下是我的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

在我的javascript文件中,我试图像这样检索我的对象:

new QWebChannel(qt.webChannelTransport, function(channel) {

var myObject = channel.objects.myObject;

});
但是,我在控制台中遇到以下错误:

错误:未定义qt

我还尝试将其替换为
navigator.qtWebChannelTransport
,但我得到了:

错误:未定义传输

谁能告诉我我做错了什么?谢谢

编辑:qt.webChannelTransport是否仅可通过Qt5.5访问?当我阅读
QWebEnginePage::setWebChannel

的文档时,似乎就是这样,这是正确的

QWebChannel
QWebEngine
的集成仅在5.5版中提供,如模块的主要开发人员Milian所述

没错


QWebChannel
QWebEngine
的集成仅在5.5版中提供,如模块的主要开发人员Milian所述

对于存在相同问题但使用Qt 5.5+的其他用户,请确保在
.pro
文件中有
Qt+=webchannel

对于存在相同问题但使用Qt 5.5+的其他用户,确保您的
.pro
文件中有
QT+=webchannel

您必须在加载url之前设置webchannel

您必须在加载url之前设置webchannel

这不是一个很好的答案。添加更多信息或示例。这更多的是一个评论。这不是一个很好的答案。添加更多信息或示例。这更像是一个评论。