javascriptc++qtqtwebengine

qt.webChannelTransport undefined in QWebEngineView


I ran into a problem using QWebChannel for accessing an object from JavaScript. I'm currently using Qt5.4.2.

Here's my CPP code :

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);

}

In my index.html, I am including qwebchannel.js :

<script type="text/javascript" src="qrc:///qtwebchannel/qwebchannel.js"></script>

And in my javascript file, I am trying to retrieve my object like this :

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

var myObject = channel.objects.myObject;

});

However, I get the following error in the console :

Error: qt is not defined

I also tried to replace it with navigator.qtWebChannelTransport but I got :

Error: transport is not defined

Can somebody tell me what did I do wrong? Thanks.

Edit : Is qt.webChannelTransport only accessible with Qt5.5? It seems to be the case when I read the doc of QWebEnginePage::setWebChannel...


Solution

  • Thats correct.

    QWebChannel integration with QWebEngine is only available from version 5.5 as stated here by Milian, the main developer of the module.