2024-10-20 05:21:03 +00:00
|
|
|
package qt6
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
#include "gen_qrunnable.h"
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
*/
|
|
|
|
import "C"
|
|
|
|
|
|
|
|
import (
|
|
|
|
"runtime"
|
2024-11-23 06:34:52 +00:00
|
|
|
"runtime/cgo"
|
2024-10-20 05:21:03 +00:00
|
|
|
"unsafe"
|
|
|
|
)
|
|
|
|
|
|
|
|
type QRunnable struct {
|
2024-11-19 06:29:06 +00:00
|
|
|
h *C.QRunnable
|
|
|
|
isSubclass bool
|
2024-10-20 05:21:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (this *QRunnable) cPointer() *C.QRunnable {
|
|
|
|
if this == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return this.h
|
|
|
|
}
|
|
|
|
|
|
|
|
func (this *QRunnable) UnsafePointer() unsafe.Pointer {
|
|
|
|
if this == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return unsafe.Pointer(this.h)
|
|
|
|
}
|
|
|
|
|
2024-11-19 06:29:06 +00:00
|
|
|
// newQRunnable constructs the type using only CGO pointers.
|
2024-10-20 05:21:03 +00:00
|
|
|
func newQRunnable(h *C.QRunnable) *QRunnable {
|
|
|
|
if h == nil {
|
|
|
|
return nil
|
|
|
|
}
|
2024-12-07 04:15:57 +00:00
|
|
|
|
2024-10-20 05:21:03 +00:00
|
|
|
return &QRunnable{h: h}
|
|
|
|
}
|
|
|
|
|
2024-11-19 06:29:06 +00:00
|
|
|
// UnsafeNewQRunnable constructs the type using only unsafe pointers.
|
2024-10-20 05:21:03 +00:00
|
|
|
func UnsafeNewQRunnable(h unsafe.Pointer) *QRunnable {
|
2024-12-07 04:15:57 +00:00
|
|
|
return newQRunnable((*C.QRunnable)(h))
|
2024-10-20 05:21:03 +00:00
|
|
|
}
|
|
|
|
|
2024-11-23 06:34:52 +00:00
|
|
|
// NewQRunnable constructs a new QRunnable object.
|
|
|
|
func NewQRunnable() *QRunnable {
|
|
|
|
|
2024-12-07 04:15:57 +00:00
|
|
|
ret := newQRunnable(C.QRunnable_new())
|
2024-11-23 06:34:52 +00:00
|
|
|
ret.isSubclass = true
|
|
|
|
return ret
|
|
|
|
}
|
|
|
|
|
2024-10-20 05:21:03 +00:00
|
|
|
func (this *QRunnable) Run() {
|
|
|
|
C.QRunnable_Run(this.h)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (this *QRunnable) AutoDelete() bool {
|
|
|
|
return (bool)(C.QRunnable_AutoDelete(this.h))
|
|
|
|
}
|
|
|
|
|
|
|
|
func (this *QRunnable) SetAutoDelete(autoDelete bool) {
|
|
|
|
C.QRunnable_SetAutoDelete(this.h, (C.bool)(autoDelete))
|
|
|
|
}
|
2024-11-23 06:34:52 +00:00
|
|
|
func (this *QRunnable) OnRun(slot func()) {
|
2024-12-07 01:43:28 +00:00
|
|
|
if !this.isSubclass {
|
|
|
|
panic("miqt: can only override virtual methods for directly constructed types")
|
|
|
|
}
|
2024-11-23 06:34:52 +00:00
|
|
|
C.QRunnable_override_virtual_Run(unsafe.Pointer(this.h), C.intptr_t(cgo.NewHandle(slot)))
|
|
|
|
}
|
|
|
|
|
|
|
|
//export miqt_exec_callback_QRunnable_Run
|
|
|
|
func miqt_exec_callback_QRunnable_Run(self *C.QRunnable, cb C.intptr_t) {
|
|
|
|
gofunc, ok := cgo.Handle(cb).Value().(func())
|
|
|
|
if !ok {
|
|
|
|
panic("miqt: callback of non-callback type (heap corruption?)")
|
|
|
|
}
|
|
|
|
|
|
|
|
gofunc()
|
|
|
|
|
|
|
|
}
|
2024-10-20 05:21:03 +00:00
|
|
|
|
|
|
|
// Delete this object from C++ memory.
|
|
|
|
func (this *QRunnable) Delete() {
|
2024-11-19 06:29:06 +00:00
|
|
|
C.QRunnable_Delete(this.h, C.bool(this.isSubclass))
|
2024-10-20 05:21:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// GoGC adds a Go Finalizer to this pointer, so that it will be deleted
|
|
|
|
// from C++ memory once it is unreachable from Go memory.
|
|
|
|
func (this *QRunnable) GoGC() {
|
|
|
|
runtime.SetFinalizer(this, func(this *QRunnable) {
|
|
|
|
this.Delete()
|
|
|
|
runtime.KeepAlive(this.h)
|
|
|
|
})
|
|
|
|
}
|