Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to invoke C++/Qt function from Javascript in QWebengine?

I have looked the Qt example about QWebChannel .

But its a C/S app. BTW it doesn't work on my computer(OS X 10.10.5, Qt5.5).

All my HTML contents come from local disk. I don't think it needs socket things.

new QWebChannel(navigator.qtWebChannelTransport, function(channel) {
    // all published objects are available in channel.objects under
    // the identifier set in their attached WebChannel.id property
    var foo = channel.objects.foo;
    // access a property
    alert(foo.hello);
    // connect to a signal
    foo.someSignal.connect(function(message) {
        alert("Got signal: " + message);
    });
    // invoke a method, and receive the return value asynchronously
    foo.someMethod("bar", function(ret) {
        alert("Got return value: " + ret);
    });
});

There is no

navigator.qtWebChannelTransport

such a thing, JS stopped there.

What should I fill with the first parameter ?


like image 916
Hunker Avatar asked Sep 26 '22 20:09

Hunker


1 Answers

For QtWebEngine, you have to use qt.webChannelTransport.

like image 93
milianw Avatar answered Oct 03 '22 02:10

milianw