Better_Software_Header_MobileBetter_Software_Header_Web

Find what you need - explore our website and developer resources

Qt WebChannel - bridging the gap between C++/QML and the web


import QtWebChannel 1.0

import QtWebKit 3.0
import QtWebKit.experimental 1.0

    QtObject {
        id: myObject

        // the identifier under which this object
        // will be known on the JavaScript side
        WebChannel.id: "foo"

        // signals, methods and properties are
        // accessible to JavaScript code
        signal someSignal(string message);

        function someMethod(message) {
            console.log(message);
            someSignal(message);
            return "foobar";
        }

        property string hello: "world"
    }

    WebView {
        experimental.webChannel.registeredObjects: [myObject]
    }

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

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

34 Comments

19 - Aug - 2014

Roger

19 - Aug - 2014

Milian Wolff

26 - Aug - 2014

rubizm

19 - Aug - 2014

Christian Feldbacher

23 - Aug - 2014

David Smid

24 - Aug - 2014

Milian Wolff

1 - Sept - 2014

QML

8 - Sept - 2014

Noam Rosenthal

9 - Sept - 2014

Milian Wolff

22 - Nov - 2014

Eric

23 - Nov - 2014

Milian Wolff

27 - Jan - 2015

Glen

27 - Jan - 2015

Milian Wolff

13 - Mar - 2015

Nehal

4 - Sept - 2015

corey

4 - Sept - 2015

Milian Wolff

9 - Sept - 2015

Siamak Rahimi Motem

10 - Sept - 2015

Alexandre Cossette-Pacheco

9 - Sept - 2015

Siamak Rahimi Motem

9 - Sept - 2015

Milian Wolff

WebEngineView {
  webChannel.registeredObjects:[foo, bar, asdf]
}

9 - Sept - 2015

Milian Wolff

6 - Nov - 2015

Jesus Sanchez

6 - Nov - 2015

Jesus Sanchez

15 - Oct - 2015

Vyacheslav

16 - Oct - 2015

Milian Wolff

3 - Nov - 2015

Ivan

3 - Nov - 2015

Milian Wolff

17 - Nov - 2015

Ivan

28 - Mar - 2017

Daniele

29 - Mar - 2017

Milian Wolff

4 - Oct - 2017

Kashif

4 - Oct - 2017

Milian Wolff

3 - Nov - 2017

Neeraj Badal

15 - Nov - 2017

Milian Wolff

MilianWolff

Milian Wolff

Senior Software Engineer