go-qml / qml

QML support for the Go language
Other
1.96k stars 189 forks source link

ObjectByName hangs on Ubuntu, works on Windows #63

Closed neclepsio closed 10 years ago

neclepsio commented 10 years ago

When calling ObjectByName under Ubuntu 14.04 64-bit, it hangs. "test2" is never printed. Under Windows 32 bit, it works. Using the gopher sample and adding ObjectByName into Init function, it works, so I don't think it's related.

It seems to hang on RunMain's "guiFunc <- f".

Thank you.

gopher.qml:

import QtQuick 2.2
import GoExtensions 1.0

Gopher {
    id: gopher
    width: 600; height: 400

    MouseArea {
        objectName: "glSceneMouseArea"
        acceptedButtons: Qt.AllButtons

        anchors.fill: parent
    }
}

gopher.go

package main

import (
    "fmt"
    "gopkg.in/qml.v0"
    "os"
)

func main() {
    filename := "gopher.qml"
    if len(os.Args) == 2 {
        filename = os.Args[1]
    }
    if err := run(filename); err != nil {
        fmt.Fprintf(os.Stderr, "error: %v\n", err)
        os.Exit(1)
    }
}

func run(filename string) error {
    qml.Init(nil)
    engine := qml.NewEngine()

    qml.RegisterTypes("GoExtensions", 1, 0, []qml.TypeSpec{{
        Init: InitGopher,
    }})

    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
}

type Gopher struct {
    qml.Object
}

func InitGopher(g *Gopher, obj qml.Object) {
    g.Object = obj
    println("test1")
    mouseArea := obj.ObjectByName("glSceneMouseArea")
    println("test2")
    mouseArea.Int("width")
}

func (r *Gopher) Paint(p *qml.Painter) {
}
niemeyer commented 10 years ago

This is not just ObjectByName, but about how the rendering thread in QML runs with the main thread blocked. This was already handled in a different scenario, but something seems to be missing. I'll get it fixed, thank you.