mirror of
https://github.com/mappu/miqt.git
synced 2025-01-02 21:58:38 +00:00
Add goroutine6
Ported from: https://github.com/therecipe/examples/blob/master/advanced/widgets/goroutine/main.go
This commit is contained in:
parent
5f7b9a47b8
commit
60022e37e7
1
.gitignore
vendored
1
.gitignore
vendored
@ -20,6 +20,7 @@ cmd/genbindings/genbindings
|
|||||||
cmd/miqt-uic/miqt-uic
|
cmd/miqt-uic/miqt-uic
|
||||||
cmd/miqt-rcc/miqt-rcc
|
cmd/miqt-rcc/miqt-rcc
|
||||||
|
|
||||||
|
examples/goroutine6/goroutine6
|
||||||
examples/helloworld/helloworld
|
examples/helloworld/helloworld
|
||||||
examples/helloworld6/helloworld6
|
examples/helloworld6/helloworld6
|
||||||
examples/mdoutliner/mdoutliner
|
examples/mdoutliner/mdoutliner
|
||||||
|
50
examples/goroutine6/main.go
Normal file
50
examples/goroutine6/main.go
Normal 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()
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user