Rick Calixte 2024-11-10 16:05:35 -05:00
parent 5f7b9a47b8
commit 60022e37e7
No known key found for this signature in database
2 changed files with 51 additions and 0 deletions

1
.gitignore vendored
View File

@ -20,6 +20,7 @@ cmd/genbindings/genbindings
cmd/miqt-uic/miqt-uic
cmd/miqt-rcc/miqt-rcc
examples/goroutine6/goroutine6
examples/helloworld/helloworld
examples/helloworld6/helloworld6
examples/mdoutliner/mdoutliner

View File

@ -0,0 +1,50 @@
package main
import (
"fmt"
"os"
"time"
qt "github.com/mappu/miqt/qt6"
)
func main() {
qt.NewQApplication(os.Args)
window := qt.NewQMainWindow2()
window.QWidget.SetFixedSize2(250, 200)
window.QWidget.SetWindowTitle("goroutine Example")
widget := qt.NewQWidget(window.QWidget)
var layout = qt.NewQVBoxLayout2()
widget.SetLayout(layout.QBoxLayout.QLayout)
window.SetCentralWidget(widget)
labels := make([]*qt.QLabel, 3)
for i := range labels {
label := qt.NewQLabel(window.QWidget)
label.SetAlignment(qt.AlignCenter)
widget.Layout().AddWidget(label.QWidget)
labels[i] = label
}
button := qt.NewQPushButton5("start!", window.QWidget)
button.OnClicked1(func(bool) {
button.SetDisabled(true)
for i, label := range labels {
go func(index int, qlabel *qt.QLabel) {
var tick int
for range time.NewTicker(time.Duration((index+1)*25) * time.Millisecond).C {
tick++
time.Sleep(50 * time.Millisecond)
qlabel.SetText(fmt.Sprintf("%v %v", tick, time.Now().UTC().Format("15:04:05.0000")))
}
}(i, label)
}
})
widget.Layout().AddWidget(button.QAbstractButton.QWidget)
window.Show()
qt.QApplication_Exec()
}