Skip to content

Commit

Permalink
Add goroutine6
Browse files Browse the repository at this point in the history
  • Loading branch information
rcalixte committed Nov 10, 2024
1 parent 3a14372 commit 5c3ce56
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
50 changes: 50 additions & 0 deletions examples/goroutine6/main.go
Original file line number Diff line number Diff line change
@@ -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)*10) * 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()
}

0 comments on commit 5c3ce56

Please sign in to comment.