go-qml / qml

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

signal slot connection fail #8

Closed eivindro closed 10 years ago

eivindro commented 10 years ago

I get a runtime panic when running the below code:

panic: object does not expose a "closeButtonClicked" signal

I got it to work fine in C++ with the same qml file.


package main

import ( "fmt" "github.com/niemeyer/qml" )

func main() { qml.Init(nil) engine := qml.NewEngine() component, err := engine.LoadFile("qmltest2.qml") if err != nil { panic(err) }

window := component.CreateWindow(nil)
component.On("closeButtonClicked", func() { fmt.Println("Close button was clicked") })

window.Show()
window.Wait()

}


import QtQuick 2.1 import QtQuick.Controls 1.0 import QtQuick.Window 2.0 import QtQuick.Layouts 1.0

Item { id: root width: 200 height: 200

signal closeButtonClicked()

ColumnLayout {
    anchors.fill: parent
    anchors.margins: 3
    spacing: 2
    Button {
        objectName: "mCloseButton"
        id: mCloseButton;
        text: qsTr("Close")
        anchors.horizontalCenter: parent.horizontalCenter
        onClicked: root.closeButtonClicked()
    }
}

}

oblitum commented 10 years ago

@eivindro, the following works:

package main

import (
    "fmt"
    "github.com/niemeyer/qml"
)

func main() {
    qml.Init(nil)
    engine := qml.NewEngine()
    component, err := engine.LoadFile("qmltest2.qml")
    if err != nil {
        panic(err)
    }

    window := component.CreateWindow(nil)
    window.Root().On("closeButtonClicked", func() { fmt.Println("Close button was clicked") })

    window.Show()
    window.Wait()
}
eivindro commented 10 years ago

@oblitum You are right your way works. Hmm, it is a bit difficult to map the QML C++ documention to go-qml sometimes. Anyway, thanks!