module "GoExtensions" is not installed

54 views
Skip to first unread message

Daniel YC Lin

unread,
May 22, 2015, 12:10:02 PM5/22/15
to go-...@googlegroups.com
I'm use go & go-qml on Archlinux with qt5 installed.

I got the error message when I execute 'ex3' (It compiles OK).

$ ./ex3
display 0x854dd60
panic: file:////home/dlin/prj/qml/ex3/ex3.qml.:2 module "GoExtensions" is not installed

goroutine 1 [running, locked to thread]:
main.main()
        /home/dlin/prj/qml/ex3/ex3.go:8 +0x5b

goroutine 17 [syscall, locked to thread]:
runtime.goexit()
        /usr/lib/go/src/runtime/asm_386.s:2287 +0x1


ex3.qml
------------
import QtQuick 2.0
import GoExtensions 1.0

Item{
  Person {
    id: person
    name: "Daniel"
  }
  Component.onCompleted: console.log("Name is", person.name)
}

ex3.go
----------
package main

import "gopkg.in/qml.v1"

func main() {
        err := qml.Run(run)
        if err != nil {
                panic(err)
        }
}

type Person struct {
        Name string
}

func run() error {
        engine := qml.NewEngine()

        component, err := engine.LoadFile("ex3.qml")
        if err != nil {
                return err
        }
        // Publishing Go types to QML
        qml.RegisterTypes("GoExtensions", 1, 0, []qml.TypeSpec{{
                Init: func(p *Person, obj qml.Object) { p.Name = "<none>" },
        }})

        win := component.CreateWindow(nil)
        win.Show()
        win.Wait()
        return nil
}

Djahma

unread,
May 22, 2015, 1:26:14 PM5/22/15
to go-...@googlegroups.com
yep, that's because you are creating your component before registering the types, therefore, 'component' is unaware of 'GoExtensions'.
To get the message:
[ `go run ex3.go` | done: 30.755864385s ]
   
2015/05/22 19:16:04 ex3.qml.:9: Name is Daniel

simply rewrite ex3.go run func like so:
func run() error {
        engine
:= qml.NewEngine()
Reply all
Reply to author
Forward
0 new messages