qml调用html中函数,javascript - How to call HTML function from QML - Stack Overflow

I want to call reload function in HTML from QML. I can call a QML function from HTML as in following code.

QML file:

import QtQuick 2.5

import QtQuick.Window 2.2

import QtWebEngine 1.0

import QtWebChannel 1.0

Window {

visible: true

width: 640

height: 480

QtObject {

id: myQmlObj

WebChannel.id: "myQmlObj";

signal someSignal(string msg);

function someFoo(msg) {

console.log(msg);

}

}

WebEngineView {

id: view

anchors.fill: parent

url: "myHtml.html"

WebChannel {

id: webChannel

registeredObjects: [myQmlObj]

}

}

}

HTML file:

var color = 1;

var webChannel;

function init() {

color = 5;

};

function createChannel(lat) {

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

webChannel = channel.objects.myQmlObj;

webChannel.someSignal.connect("someSignal");

webChannel.someFoo("someFoo");

});

}

function reload(id) {

color = id;

}

Like i can call someFoo() from HTML, But i can't call reload function of HTML from my qml.

你可能感兴趣的:(qml调用html中函数)