[Qtwebengine] Handle frames and web forms with QWebEngine

Eduard Takhtamirov gibbopotam at gmail.com
Tue Feb 16 18:56:33 CET 2016

My example (in the very wild)

1. C++ code

channel = new QWebChannel(); // channel is a QWebChannel * type object
page->setWebChannel(channel); // page is a QWebEnginePage* type object
myJavaScriptWork = new JavaScriptWork();  // The class JavaScriptWork
has public methods to be called by JavaScript on the Web page, in
particular mySpecialMethod()
channel->registerObject(QStringLiteral("jsworker"), myJavaScriptWork);
// jsworker will be accessible by JavaScript on the Web page

    void mySpecialMethod(void);

2. JavaScript code on our Web server:

 // to see if it's our special browser, but don't die if not
try {
    /* qwebchannel.js should be present and invoked,
http://doc.qt.io/qt-5/qtwebchannel-javascript.html */
    new QWebChannel(qt.webChannelTransport, function (channel) {
        var jsworker = channel.objects.jsworker;
        jsworker.mySpecialMethod(); // run our C++ method
} catch (err) {
    // probably a default browser

Good luck
Ed Takhtamirov

More information about the QtWebEngine mailing list