-
Notifications
You must be signed in to change notification settings - Fork 364
/
main.qml
59 lines (54 loc) · 1.29 KB
/
main.qml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import QtQuick 2.15
import QtQuick.Window 2.15
import QtQuick.Controls 2.15
import Test 1.0
Window {
width: 640
height: 480
visible: true
title: qsTr("Hello GongJianBo")
CppObject {
id: cpp_obj
}
Column {
anchors.centerIn: parent
spacing: 12
Button {
text: "invoke"
onClicked: {
cpp_obj.doInvoke(1992, qml_obj)
}
}
Button {
text: "qml callback"
onClicked: {
doSomething(1992, cpp_obj.cppFunc)
}
}
Button {
text: "cpp callback"
onClicked: {
//传递js函数作为回调函数
cpp_obj.doSomething(1992, function(val, flag){
console.log("qml function run", val, flag);
return "qml return value";
})
}
}
}
Item {
id: qml_obj
objectName: "qml_obj"
function qmlFunc(val)
{
console.log("qml function run", val);
return "qml return value";
}
}
function doSomething(val, func)
{
console.log("qml doSomething", val);
var ret = func(val);
console.log("qml callback ret:", ret);
}
}