/
main.go
47 lines (39 loc) · 909 Bytes
/
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
package main
import (
"io/ioutil"
"log"
"os"
"strings"
funk "github.com/thoas/go-funk"
"github.com/kitech/qt.go/qtcore"
"github.com/kitech/qt.go/qtqml"
"github.com/kitech/qt.go/qtquickwidgets"
"github.com/kitech/qt.go/qtrt"
"github.com/kitech/qt.go/qtwidgets"
)
func main() {
file := "./main.qml"
if len(os.Args) > 1 {
file = os.Args[1]
}
bcc, err := ioutil.ReadFile(file)
qtrt.ErrPrint(err, file)
if err != nil {
os.Exit(1)
}
iswin := funk.Contains(strings.Split(string(bcc), "\n"), "Window {")
app := qtwidgets.NewQApplication(len(os.Args), os.Args, 0)
if iswin {
log.Println("app mod qml:")
qmle := qtqml.NewQQmlApplicationEngine(nil)
qmle.AddImportPath("./")
qmle.Load1(file)
} else {
log.Println("rect mod qml:")
qw := qtquickwidgets.NewQQuickWidget(nil)
qw.Engine().AddImportPath("./")
qw.SetSource(qtcore.NewQUrl1(file, 0))
qw.Show()
}
app.Exec()
}