-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
68 lines (48 loc) · 2.1 KB
/
main.go
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
66
67
68
package main
import (
"os"
"unsafe"
_ "github.com/therecipe/qt/interop/swift"
"github.com/therecipe/qt/core"
"github.com/therecipe/qt/qml"
"github.com/therecipe/qt/quick"
_ "github.com/therecipe/qt/quickcontrols2" //used from swift
"github.com/therecipe/qt/widgets"
"github.com/therecipe/qt/interop"
)
func main() {
core.QCoreApplication_SetAttribute(core.Qt__AA_EnableHighDpiScaling, true)
widgets.NewQApplication(len(os.Args), os.Args)
var qmlEngine *qml.QQmlEngine
interopEngine := interop.PseudoQJSEngine_qjsEngine(nil)
// setup the go widget
gw := widgets.NewQGroupBox2("Go Widget", nil)
l := widgets.NewQVBoxLayout2(gw)
callDart := widgets.NewQPushButton2("Go calls Swift", nil)
callDart.ConnectClicked(func(bool) {
interopEngine.GlobalObject().Property("swiftFunction").Call([]*interop.PseudoQJSValue{interopEngine.NewGoType("Hello from Go")})
})
l.AddWidget(callDart, 0, 0)
callQml := widgets.NewQPushButton2("Go calls Qml", nil)
callQml.ConnectClicked(func(bool) {
qmlEngine.GlobalObject().Property("qml").Property("qmlFunction").Call([]*qml.QJSValue{qmlEngine.NewGoType("Hello from Go")})
})
l.AddWidget(callQml, 0, 0)
interopEngine.GlobalObject().SetProperty("goFunction", interopEngine.NewGoType(func(s string) { println("go: " + s) }))
// setup the swift widget
interopEngine.GlobalObject().SetProperty("goSetupFunction", interopEngine.NewGoType(func() {
quickWidget := quick.NewQQuickWidgetFromPointer(unsafe.Pointer(uintptr(interopEngine.GlobalObject().Property("quickWidget").CallMethod("Pointer", nil).ToULongLong(nil))))
qmlEngine = quickWidget.Engine()
hw := widgets.NewQWidgetFromPointer(unsafe.Pointer(uintptr(interopEngine.GlobalObject().Property("swiftWidget").CallMethod("Pointer", nil).ToULongLong(nil))))
qmlEngine.GlobalObject().SetProperty("goFunction", qmlEngine.NewGoType(func(s string) { println("go: " + s) }))
win := widgets.NewQWidget(nil, 0)
win.SetWindowTitle(hw.WindowTitle())
l := widgets.NewQHBoxLayout2(win)
l.AddWidget(hw, 0, 0)
l.AddWidget(gw, 0, 0)
l.AddWidget(quickWidget, 0, 0)
win.Show()
}))
//
widgets.QApplication_Exec()
}