go-qt5: github.com/linuxdeepin/go-qt5 Index | Files | Directories

package qml

import "github.com/linuxdeepin/go-qt5"

Package qml offers graphical QML application support for the Go language.

Warning

This package is in an alpha stage, and still in heavy development. APIs may change, and things may break.

At this time contributors and developers that are interested in tracking the development closely are encouraged to use it. If you'd prefer a more stable release, please hold on a bit and subscribe to the mailing list for news. It's in a pretty good state, so it shall not take too long.

See http://github.com/niemeyer/qml for details.

Index

Package Files

bridge.go datatype.go log.go qml.go stats.go

func Changed Uses

func Changed(value, fieldAddr interface{})

Changed notifies all QML bindings that the given field value has changed.

For example:

qml.Changed(&value, &value.Field)

func CollectStats Uses

func CollectStats(enabled bool)

func Flush Uses

func Flush()

Flush synchronously flushes all pending QML activities.

func Init Uses

func Init(options *InitOptions)

Init initializes the qml package with the provided parameters. If the options parameter is nil, default options suitable for a normal graphic application will be used.

Init must be called only once, and before any other functionality from the qml package is used.

func Lock Uses

func Lock()

Lock freezes all QML activity by blocking the main event loop. Locking is necessary before updating shared data structures without race conditions.

It's safe to use qml functionality while holding a lock, as long as the requests made do not depend on follow up QML events to be processed before returning. If that happens, the problem will be observed as the application freezing.

The Lock function is reentrant. That means it may be called multiple times, and QML activities will only be resumed after Unlock is called a matching number of times.

func RegisterSingleton Uses

func RegisterSingleton(spec *TypeSpec) error

func RegisterType Uses

func RegisterType(spec *TypeSpec) error

func ResetStats Uses

func ResetStats()

func SetLogger Uses

func SetLogger(logger interface{})

SetLogger sets the target for messages logged by the qml package, including console.log and related calls from within qml code.

The logger value must implement either the StdLogger interface, which is satisfied by the standard *log.Logger type, or the QmlLogger interface, which offers more control over the logged message.

If no logger is provided, the qml package will send messages to the default log package logger. This behavior may also be restored by providing a nil logger to this function.

func Unlock Uses

func Unlock()

Unlock releases the QML event loop. See Lock for details.

type Common Uses

type Common struct {
    // contains filtered or unexported fields
}

Common implements the common behavior of all QML objects. It implements the Object interface.

func (*Common) Bool Uses

func (obj *Common) Bool(property string) bool

Bool returns the bool value of the named property. Bool panics if the property is not a bool.

func (*Common) Call Uses

func (obj *Common) Call(method string, params ...interface{}) interface{}

Call calls the given object method with the provided parameters. Call panics if the method does not exist.

func (*Common) Color Uses

func (obj *Common) Color(property string) color.RGBA

Color returns the RGBA value of the named property. Color panics if the property is not a color.

func (*Common) Common Uses

func (obj *Common) Common() *Common

Common returns obj itself.

This provides access to the underlying *Common for types that embed it, when these are used via the Object interface.

func (*Common) Create Uses

func (obj *Common) Create(ctx *Context) Object

Create creates a new instance of the component held by obj. The component instance runs under the ctx context. If ctx is nil, it runs under the same context as obj.

The Create method panics if called on an object that does not represent a QML component.

func (*Common) CreateWindow Uses

func (obj *Common) CreateWindow(ctx *Context) *Window

CreateWindow creates a new instance of the component held by obj, and creates a new window holding the instance as its root object. The component instance runs under the ctx context. If ctx is nil, it runs under the same context as obj.

The CreateWindow method panics if called on an object that does not represent a QML component.

func (*Common) Destroy Uses

func (obj *Common) Destroy()

Destroy finalizes the value and releases any resources used. The value must not be used after calling this method.

func (*Common) Float64 Uses

func (obj *Common) Float64(property string) float64

Float64 returns the float64 value of the named property. Float64 panics if the property cannot be represented as float64.

func (*Common) Int Uses

func (obj *Common) Int(property string) int

Int returns the int value of the named property. Int panics if the property cannot be represented as an int.

func (*Common) Int64 Uses

func (obj *Common) Int64(property string) int64

Int64 returns the int64 value of the named property. Int64 panics if the property cannot be represented as an int64.

func (*Common) Object Uses

func (obj *Common) Object(property string) Object

Object returns the object value of the named property. Object panics if the property is not a QML object.

func (*Common) ObjectByName Uses

func (obj *Common) ObjectByName(objectName string) Object

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 (*Common) On Uses

func (obj *Common) On(signal string, function interface{})

On connects the named signal from obj with the provided function, so that when obj next emits that signal, the function is called with the parameters the signal carries.

The provided function must accept a number of parameters that is equal to or less than the number of parameters provided by the signal, and the resepctive parameter types must match exactly or be conversible according to normal Go rules.

For example:

obj.On("clicked", func() { fmt.Println("obj got a click") })

Note that Go uses the real signal name, rather than the one used when defining QML signal handlers ("clicked" rather than "onClicked").

For more details regarding signals and QML see:

http://qt-project.org/doc/qt-5.0/qtqml/qml-qtquick2-connections.html

func (*Common) Property Uses

func (obj *Common) Property(name string) interface{}

Property returns the current value for a property of the object. If the property type is known, type-specific methods such as Int and String are more convenient to use. Property panics if the property does not exist.

func (*Common) Set Uses

func (obj *Common) Set(property string, value interface{}) error

Set changes the named object property to the given value.

func (*Common) String Uses

func (obj *Common) String(property string) string

String returns the string value of the named property. String panics if the property is not a string.

type Context Uses

type Context struct {
    Common
}

Context represents a QML context that can hold variables visible to logic running within it.

func (*Context) SetVar Uses

func (ctx *Context) SetVar(name string, value interface{})

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 (*Context) SetVars Uses

func (ctx *Context) SetVars(value interface{})

SetVars makes the exported fields of the provided value available as variables for QML code executed within the c context. The variable names will have the same name of the Go field names, 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 (*Context) Var Uses

func (ctx *Context) Var(name string) interface{}

Var returns the context variable with the given name.

type Engine Uses

type Engine struct {
    // contains filtered or unexported fields
}

Engine provides an environment for instantiating QML components.

func NewEngine Uses

func NewEngine() *Engine

NewEngine returns a new QML engine.

The Destory method must be called to finalize the engine and release any resources used.

func (*Engine) Context Uses

func (e *Engine) Context() *Context

Context returns the engine's root context.

func (*Engine) Destroy Uses

func (e *Engine) Destroy()

Destroy finalizes the engine and releases any resources used. The engine must not be used after calling this method.

It is safe to call Destroy more than once.

func (*Engine) Load Uses

func (e *Engine) Load(location string, r io.Reader) (Object, error)

Load loads a new component with the provided location and with the content read from r. The location informs the resource name for logged messages, and its path is used to locate any other resources referenced by the QML content.

Once a component is loaded, component instances may be created from the resulting object via its Create and CreateWindow methods.

func (*Engine) LoadFile Uses

func (e *Engine) LoadFile(path string) (Object, error)

LoadFile loads a component from the provided QML file. Resources referenced by the QML content will be resolved relative to its path.

Once a component is loaded, component instances may be created from the resulting object via its Create and CreateWindow methods.

func (*Engine) LoadString Uses

func (e *Engine) LoadString(location, qml string) (Object, error)

LoadString loads a component from the provided QML string. The location informs the resource name for logged messages, and its path is used to locate any other resources referenced by the QML content.

Once a component is loaded, component instances may be created from the resulting object via its Create and CreateWindow methods.

type InitOptions Uses

type InitOptions struct {
}

InitOptions holds options to initialize the qml package.

type LogMessage Uses

type LogMessage interface {
    Severity() LogSeverity
    Text() string
    File() string
    Line() int

    String() string // returns "file:line: text"
    // contains filtered or unexported methods
}

LogMessage is implemented by values provided to QmlLogger.QmlOutput.

type LogSeverity Uses

type LogSeverity int
const (
    LogDebug LogSeverity = iota
    LogWarning
    LogCritical
    LogFatal
)

type Object Uses

type Object interface {
    Common() *Common
    Set(property string, value interface{}) error
    Property(name string) interface{}
    Int(property string) int
    Int64(property string) int64
    Float64(property string) float64
    Bool(property string) bool
    String(property string) string
    Color(property string) color.RGBA
    Object(property string) Object
    ObjectByName(objectName string) Object
    Call(method string, params ...interface{}) interface{}
    Create(ctx *Context) Object
    CreateWindow(ctx *Context) *Window
    Destroy()
    On(signal string, function interface{})
}

Object is the common interface implemented by all QML types.

See the documentation of Common for details about this interface.

type QmlLogger Uses

type QmlLogger interface {
    // QmlOutput is called whenever a new message is available for logging.
    // The message value must not be used after the method returns.
    QmlOutput(message LogMessage) error
}

The QmlLogger interface may be implemented to better control how log messages from the qml package are handled. Values that implement either StdLogger or QmlLogger may be provided to the SetLogger function.

type Statistics Uses

type Statistics struct {
    EnginesAlive     int
    ValuesAlive      int
    ConnectionsAlive int
}

func Stats Uses

func Stats() (snapshot Statistics)

type StdLogger Uses

type StdLogger interface {
    // Output is called whenever a new message is available for logging.
    // See the standard log.Logger type for more details.
    Output(calldepth int, s string) error
}

The StdLogger interface is implemented by standard *log.Logger values. Values that implement either StdLogger or QmlLogger may be provided to the SetLogger function.

type TypeSpec Uses

type TypeSpec struct {
    Location     string
    Major, Minor int
    // TODO Consider refactoring this type into ModuleSpec for the above + []TypeSpec for the below
    Name string
    New  func() interface{}
}

type Window Uses

type Window struct {
    Common
}

Window represents a QML window where components are rendered.

func (*Window) Hide Uses

func (win *Window) Hide()

Hide hides the window.

func (*Window) Root Uses

func (win *Window) Root() Object

Root returns the root object being rendered.

If the window was defined in QML code, the root object is the window itself.

func (*Window) Show Uses

func (win *Window) Show()

Show exposes the window.

func (*Window) Snapshot Uses

func (win *Window) Snapshot() image.Image

Snapshot returns an image with the visible contents of the window. The main GUI thread is paused while the data is being acquired.

func (*Window) Wait Uses

func (win *Window) Wait()

Wait blocks the current goroutine until the window is closed.

Directories

PathSynopsis
tref

Package qml imports 19 packages (graph). Updated 2018-12-12. Refresh now. Tools for package owners.