therecipe / qt

Qt binding for Go (Golang) with support for Windows / macOS / Linux / FreeBSD / Android / iOS / Sailfish OS / Raspberry Pi / AsteroidOS / Ubuntu Touch / JavaScript / WebAssembly
GNU Lesser General Public License v3.0
10.5k stars 748 forks source link

Signal/Slot Issue #1237

Closed hiteshhedwig closed 3 years ago

hiteshhedwig commented 3 years ago

Hi,

I am getting started with QT with Golang. Not an expert at all. So, if i say something that is lame, Please correct me. I am struggling to figure out how to use Signal/Slots in Go. Tried lot of examples as provided in this repo. But doesn't work.

As pointed out in this link : Link


package main

import (
    "fmt"
    "os"

    "github.com/therecipe/qt/core"
)

type hStruct struct {
    core.QObject

    _ func() `signal:"mySignal,auto"`
}

func (h *hStruct) mySignal() {
    fmt.Println("current thread (mySignal):", core.QThread_CurrentThread().Pointer())
}

func main() {
    core.NewQCoreApplication(len(os.Args), os.Args)

    fmt.Println("current thread (main):", core.QThread_CurrentThread().Pointer())

    h := NewHStruct(nil)

    go h.MySignal()

    core.QCoreApplication_Exec()
}

I follow it as said, but throws an error :

# command-line-arguments
zone/signalslots.go:19:3: h.ConnectMySignal undefined (type *hStruct has no field or method ConnectMySignal)
zone/signalslots.go:31:7: undefined: NewHStruct

How should signal & slots be taken care of in go? Any suggestions?