func run(filename string) error { qml.Init(nil) engine := qml.NewEngine() model, err := Read("model/gopher.obj") if err != nil { return err } qml.RegisterTypes("GoExtensions", 1, 0, []qml.TypeSpec{{ Init: func(g *Gopher, obj qml.Object) { g.Object = obj g.model = model }, }}) component, err := engine.LoadFile(filename) if err != nil { return err } win := component.CreateWindow(nil) win.Set("x", 560) win.Set("y", 320) win.Show() win.Wait() return nil }
func run() error { qml.Init(nil) qml.RegisterTypes("GoExtensions", 1, 0, []qml.TypeSpec{{ Init: func(r *GoRect, obj qml.Object) { r.Object = obj }, }}) engine := qml.NewEngine() component, err := engine.LoadFile("painting.qml") if err != nil { return err } win := component.CreateWindow(nil) win.Show() win.Wait() return nil }
func run() error { qml.Init(nil) qml.RegisterTypes("GoExtensions", 1, 0, []qml.TypeSpec{{ Init: func(v *GoType, obj qml.Object) {}, }, { Init: func(v *GoSingleton, obj qml.Object) { v.Event = "birthday" }, Singleton: true, }}) engine := qml.NewEngine() component, err := engine.LoadFile("customtype.qml") if err != nil { return err } value := component.Create(nil) fmt.Println("Text is:", value.Interface().(*GoType).Text) return nil }
func (s *S) TestTable(c *C) { var testData TestData types := []qml.TypeSpec{{ Init: func(v *GoType, obj qml.Object) { v.object = obj v.StringValue = "<initial>" testData.createdValue = append(testData.createdValue, v) }, }, { Name: "NamedGoType", Init: func(v *GoType, obj qml.Object) { v.object = obj v.StringValue = "<initial>" testData.createdValue = append(testData.createdValue, v) }, }, { Name: "GoSingleton", Init: func(v *GoType, obj qml.Object) { v.object = obj v.StringValue = "<initial>" testData.createdSingleton = append(testData.createdSingleton, v) }, Singleton: true, }, { Init: func(v *GoRect, obj qml.Object) { testData.createdRect = append(testData.createdRect, v) }, }} qml.RegisterTypes("GoTypes", 4, 2, types) filter := regexp.MustCompile("") if tablef != nil { filter = regexp.MustCompile(*tablef) } for i := range tests { s.TearDownTest(c) t := &tests[i] header := fmt.Sprintf("----- Running table test %d: %s -----", i, t.Summary) if !filter.MatchString(header) { continue } c.Log(header) s.SetUpTest(c) value := t.Value s.context.SetVar("value", &value) testData = TestData{ C: c, value: &value, engine: s.engine, context: s.context, } if t.Init != nil { t.Init(&testData) if c.Failed() { c.FailNow() } } component, err := s.engine.LoadString("file.qml", "import QtQuick 2.0\nimport GoTypes 4.2\n"+strings.TrimSpace(t.QML)) c.Assert(err, IsNil) logMark := c.GetTestLog() // The component instance is destroyed before the loop ends below, // but do a defer to ensure it will be destroyed if the test fails. root := component.Create(nil) defer root.Destroy() testData.component = component testData.root = root if t.QMLLog != "" { logged := c.GetTestLog()[len(logMark):] if t.QMLLog[0] == '!' { c.Check(logged, Not(Matches), "(?s).*"+t.QMLLog[1:]+".*") } else { c.Check(logged, Matches, "(?s).*"+t.QMLLog+".*") } } if !reflect.DeepEqual(t.QMLValue, GoType{}) { c.Check(value.StringValue, Equals, t.QMLValue.StringValue) c.Check(value.BoolValue, Equals, t.QMLValue.BoolValue) c.Check(value.IntValue, Equals, t.QMLValue.IntValue) c.Check(value.Int64Value, Equals, t.QMLValue.Int64Value) c.Check(value.Int32Value, Equals, t.QMLValue.Int32Value) c.Check(value.Float64Value, Equals, t.QMLValue.Float64Value) c.Check(value.Float32Value, Equals, t.QMLValue.Float32Value) c.Check(value.AnyValue, Equals, t.QMLValue.AnyValue) c.Check(value.IntsValue, DeepEquals, t.QMLValue.IntsValue) c.Check(value.MapValue, DeepEquals, t.QMLValue.MapValue) } if !c.Failed() { logMark := c.GetTestLog() if t.Done != nil { t.Done(&testData) } if t.DoneLog != "" { logged := c.GetTestLog()[len(logMark):] if t.DoneLog[0] == '!' { c.Check(logged, Not(Matches), "(?s).*"+t.DoneLog[1:]+".*") } else { c.Check(logged, Matches, "(?s).*"+t.DoneLog+".*") } } if !reflect.DeepEqual(t.DoneValue, GoType{}) { c.Check(value.StringValue, Equals, t.DoneValue.StringValue) c.Check(value.BoolValue, Equals, t.DoneValue.BoolValue) c.Check(value.IntValue, Equals, t.DoneValue.IntValue) c.Check(value.Int64Value, Equals, t.DoneValue.Int64Value) c.Check(value.Int32Value, Equals, t.DoneValue.Int32Value) c.Check(value.Float64Value, Equals, t.DoneValue.Float64Value) c.Check(value.Float32Value, Equals, t.DoneValue.Float32Value) c.Check(value.AnyValue, Equals, t.DoneValue.AnyValue) c.Check(value.IntsValue, DeepEquals, t.DoneValue.IntsValue) c.Check(value.MapValue, DeepEquals, t.DoneValue.MapValue) } } root.Destroy() if c.Failed() { c.FailNow() // So relevant logs are at the bottom. } } }