I'm working on program with use Golang and Qt. I have a problem with Qthread for a heavy task.
This is my code:
MainUi.go
// Start new thread first
workThread := core.NewQThread(nil)
workThread.Start()
// Start a worker
wkr := worker.InitWorkPool()
wkr.MoveToThread(workThread)
wkr.ConnectReportOne(func(v0 int, v1 int) {
// I put this code here to check is it called but not see anything
fmt.Println("Report One")
label1.SetText(strconv.Itoa(v0))
label2.SetText(strconv.Itoa(v1))
}
wkr.ConnectReportTwo(func(v0 int, v1 int, v2 int) {
label3.SetText(strconv.Itoa(v0))
label4.SetText(strconv.Itoa(v1))
label5.SetText(strconv.Itoa(v2))
}
wkr.ConnectFinished(func() {
widgets.QMessageBox_Information(nil, "Finished", "Task finished", widgets.QMessageBox__Ok, widgets.QMessageBox__Ok)
}
wkr.Run()
Worker.go
type WorkPool struct {
core.QObject
_ func(int, int) `signal:"reportOne"`
_ func() `signal:"finished"`
_ func(int, int, int) `signal:"reportTwo"`
}
func InitWorkPool() *WorkPool {
return &WorkPool{}
}
func (wp *WorkPool) Run() {
wp.ReportOne(11, 12) // This func not work
wp.ReportTwo(21, 22, 23) // This func not work
/* Do some stuff */
wp.Finished() //This func work
}
I ran qtmoc
to generation some addition code.
A function wp.Finished()
work if I call it first or via another function like StopTask()
. But wp.ReportOne()
and wp.ReportTwo()
not work and freeze MainUi
.
Anyone can tell me what wrong in my code. It took me 2 days.
Thanks for reading.