Skip to content

Commit

Permalink
Added Value.Create.
Browse files Browse the repository at this point in the history
  • Loading branch information
niemeyer committed Sep 17, 2013
1 parent 2478289 commit bb15c59
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
8 changes: 8 additions & 0 deletions all_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,14 @@ var tests = []struct {
Done: func(d *TestData) { d.compinst.Call("log", d.compinst) },
DoneLog: "Width is 300",
},
{
Summary: "Create a QML-defined component in Go",
QML: `Item { property var comp: Component { Rectangle { width: 300 } } }`,
Done: func(d *TestData) {
rect := d.compinst.Field("comp").(*qml.Value).Create(nil)
d.Assert(rect.Field("width"), Equals, float64(300))
},
},
}

var tablef = flag.String("tablef", "", "if provided, TestTable only runs tests with a summary matching the regexp")
Expand Down
3 changes: 3 additions & 0 deletions cpp/capi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ QObject_ *componentCreate(QQmlComponent_ *component, QQmlContext_ *context)
QQmlComponent *qcomponent = reinterpret_cast<QQmlComponent *>(component);
QQmlContext *qcontext = reinterpret_cast<QQmlContext *>(context);

if (!qcontext) {
qcontext = qmlContext(qcomponent);
}
return qcomponent->create(qcontext);
}

Expand Down
14 changes: 14 additions & 0 deletions qml.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,20 @@ func (o *commonObject) Call(method string, params ...interface{}) interface{} {
return unpackDataValue(&result, o.engine)
}

func (o *commonObject) Create(context *Context) *Value {
// TODO Fail if o does not represent a component.
var value Value
value.engine = o.engine
gui(func() {
ctxaddr := nilPtr
if context != nil {
ctxaddr = context.addr
}
value.addr = C.componentCreate(o.addr, ctxaddr)
})
return &value
}

// Destroy finalizes the value and releases any resources used.
// The value must not be used after calling this method.
func (o *commonObject) Destroy() {
Expand Down

0 comments on commit bb15c59

Please sign in to comment.