-
Notifications
You must be signed in to change notification settings - Fork 364
/
main.qml
65 lines (61 loc) · 1.7 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
60
61
62
63
64
65
import QtQuick 2.15
import QtQuick.Window 2.15
import QtQuick.Controls 2.15
import GongJianBo 1.0
Window {
width: 640
height: 480
visible: true
title: qsTr("Qml Struct")
property var callback
Column {
anchors.centerIn: parent
spacing: 12
Button {
text: "Data"
onClicked: {
// 测试自定义类型
var data = CppTool.createData()
data.name = "qml set name"
console.log("typeof", typeof data)
// 直接回调
CppTool.setData(data)
// QML中持有引用,再回调
callback = function() {
CppTool.setData(data)
}
}
}
Button {
text: "Meta"
onClicked: {
// 测试Qt自带类型
var data = CppTool.createMeta()
console.log("typeof", typeof data)
// 直接回调
CppTool.setMeta(data)
// QML中持有引用,再回调
callback = function() {
CppTool.setMeta(data)
}
}
}
Button {
text: "Callback"
onClicked: {
// QImage/QPixmap这种稀缺资源类型,QML不会持有其引用,生成之后可以立即使用但没法用变量暂存
if (callback) {
callback()
callback = null
}
}
}
Button {
text: "QML GC"
onClicked: {
console.log("gc")
gc()
}
}
}
}