本文整理匯總了Golang中C.newString函數的典型用法代碼示例。如果您正苦於以下問題:Golang newString函數的具體用法?Golang newString怎麽用?Golang newString使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了newString函數的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: ObjectByName
// ObjectByName returns the Object value of the descendant object that
// was defined with the objectName property set to the provided value.
// ObjectByName panics if the object is not found.
func (obj *Common) ObjectByName(objectName string) Object {
cname, cnamelen := unsafeStringData(objectName)
var dvalue C.DataValue
var object Object
RunMain(func() {
qname := C.newString(cname, cnamelen)
defer C.delString(qname)
C.objectFindChild(obj.addr, qname, &dvalue)
// unpackDataValue will also initialize the Go type, if necessary.
value := unpackDataValue(&dvalue, obj.engine)
if dvalue.dataType == C.DTGoAddr {
datap := unsafe.Pointer(&dvalue.data)
fold := (*(**valueFold)(datap))
if fold.init.IsValid() {
panic("internal error: custom Go type not initialized")
}
object = &Common{fold.cvalue, fold.engine, newConnections()}
} else {
object, _ = value.(Object)
}
})
// if object == nil {
// panic(fmt.Sprintf("cannot find descendant with objectName == %q", objectName))
// }
return object
}
示例2: Var
// Var returns the context variable with the given name.
func (ctx *Context) Var(name string) interface{} {
cname, cnamelen := unsafeStringData(name)
var dvalue C.DataValue
gui(func() {
qname := C.newString(cname, cnamelen)
defer C.delString(qname)
C.contextGetProperty(ctx.addr, qname, &dvalue)
})
return unpackDataValue(&dvalue, ctx.engine)
}
示例3: SetVar
// SetVar makes the provided value available as a variable with the
// given name for QML code executed within the c context.
//
// If value is a struct, its exported fields are also made accessible to
// QML code as attributes of the named object. The attribute name in the
// object has the same name of the Go field name, except for the first
// letter which is lowercased. This is conventional and enforced by
// the QML implementation.
//
// The engine will hold a reference to the provided value, so it will
// not be garbage collected until the engine is destroyed, even if the
// value is unused or changed.
func (ctx *Context) SetVar(name string, value interface{}) {
cname, cnamelen := unsafeStringData(name)
gui(func() {
var dvalue C.DataValue
packDataValue(value, &dvalue, ctx.engine, cppOwner)
qname := C.newString(cname, cnamelen)
defer C.delString(qname)
C.contextSetProperty(ctx.addr, qname, &dvalue)
})
}
示例4: AddImageProvider
// AddImageProvider registers f to be called when an image is requested by QML code
// with the specified provider identifier. It is a runtime error to register the same
// provider identifier multiple times.
//
// The imgId provided to f is the requested image source, with the "image:" scheme
// and provider identifier removed. For example, with an image image source of
// "image://myprovider/icons/home.ext", the respective imgId would be "icons/home.ext".
//
// If either the width or the height parameters provided to f are zero, no specific
// size for the image was requested. If non-zero, the returned image should have the
// the provided size, and will be resized if the returned image has a different size.
//
// See the documentation for more details on image providers:
//
// http://qt-project.org/doc/qt-5.0/qtquick/qquickimageprovider.html
//
func (e *Engine) AddImageProvider(prvId string, f func(imgId string, width, height int) image.Image) {
if _, ok := e.imageProviders[prvId]; ok {
panic(fmt.Sprintf("engine already has an image provider with id %q", prvId))
}
e.imageProviders[prvId] = &f
cprvId, cprvIdLen := unsafeStringData(prvId)
gui(func() {
qprvId := C.newString(cprvId, cprvIdLen)
defer C.delString(qprvId)
C.engineAddImageProvider(e.addr, qprvId, unsafe.Pointer(&f))
})
}
示例5: ObjectByName
// ObjectByName returns the Object value of the descendant object that
// was defined with the objectName property set to the provided value.
// ObjectByName panics if the object is not found.
func (obj *Common) ObjectByName(objectName string) Object {
cname, cnamelen := unsafeStringData(objectName)
var dvalue C.DataValue
gui(func() {
qname := C.newString(cname, cnamelen)
defer C.delString(qname)
C.objectFindChild(obj.addr, qname, &dvalue)
})
object, ok := unpackDataValue(&dvalue, obj.engine).(Object)
if !ok {
panic(fmt.Sprintf("cannot find descendant with objectName == %q", objectName))
}
return object
}