mirror of
https://github.com/mappu/miqt.git
synced 2025-01-21 22:20:38 +00:00
initial commit
This commit is contained in:
commit
fea87aff42
28
binding.cpp
Normal file
28
binding.cpp
Normal file
@ -0,0 +1,28 @@
|
||||
#include "binding.h"
|
||||
#include <QApplication>
|
||||
#include <QWidget>
|
||||
#include <QPushButton>
|
||||
|
||||
PQApplication QApplication_new(int argc, char** argv) {
|
||||
return new QApplication(argc, argv);
|
||||
}
|
||||
|
||||
PQWidget QWidget_new() {
|
||||
return new QWidget();
|
||||
}
|
||||
|
||||
void QWidget_show(PQWidget self) {
|
||||
static_cast<QWidget*>(self)->show();
|
||||
}
|
||||
|
||||
PQPushButton QPushButton_new(const char* label, PQWidget parent) {
|
||||
return new QPushButton(label, static_cast<QWidget*>(parent));
|
||||
}
|
||||
|
||||
void QPushButton_show(PQPushButton self) {
|
||||
static_cast<QPushButton*>(self)->show();
|
||||
}
|
||||
|
||||
int QApplication_exec(PQApplication self) {
|
||||
return static_cast<QApplication*>(self)->exec();
|
||||
}
|
74
binding.go
Normal file
74
binding.go
Normal file
@ -0,0 +1,74 @@
|
||||
package main
|
||||
|
||||
/*
|
||||
|
||||
#cgo pkg-config: Qt5Widgets
|
||||
#include "binding.h"
|
||||
|
||||
*/
|
||||
import "C"
|
||||
|
||||
import (
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
func CArray(data []string) (C.int, **C.char) {
|
||||
|
||||
c_argv := (*[0xfff]*C.char)(C.malloc(C.ulong(8 /* sizeof pointer */ * len(data))))
|
||||
|
||||
for i, arg := range data {
|
||||
c_argv[i] = C.CString(arg)
|
||||
}
|
||||
|
||||
return C.int(len(data)), (**C.char)(unsafe.Pointer(c_argv))
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
type QApplication struct {
|
||||
h C.PQApplication
|
||||
}
|
||||
|
||||
func NewQApplication(args []string) *QApplication {
|
||||
h := C.QApplication_new(CArray(args))
|
||||
return &QApplication{h: h}
|
||||
}
|
||||
|
||||
func (this *QApplication) Exec() int {
|
||||
ret := C.QApplication_exec(this.h)
|
||||
return int(ret)
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
type QWidget struct {
|
||||
h C.PQWidget
|
||||
}
|
||||
|
||||
func NewQWidget() *QWidget {
|
||||
ret := C.QWidget_new()
|
||||
return &QWidget{h: ret}
|
||||
}
|
||||
|
||||
func (this *QWidget) Show() {
|
||||
C.QWidget_show(this.h)
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
type QPushButton struct {
|
||||
h C.PQPushButton
|
||||
}
|
||||
|
||||
func NewQPushButton(label string, parent QWidget) *QPushButton {
|
||||
h := C.QPushButton_new(C.CString(label), parent.h)
|
||||
return &QPushButton{h: h}
|
||||
}
|
||||
|
||||
func (this *QPushButton) Show() {
|
||||
C.QPushButton_show(this.h)
|
||||
}
|
||||
|
||||
func (this *QPushButton) AsQWidget() *QWidget {
|
||||
return &QWidget{h: C.PQWidget(this.h)} // Type cast
|
||||
}
|
25
binding.h
Normal file
25
binding.h
Normal file
@ -0,0 +1,25 @@
|
||||
typedef void* PQApplication;
|
||||
|
||||
typedef void* PQPushButton;
|
||||
|
||||
typedef void* PQWidget;
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
PQApplication QApplication_new(int argc, char** argv);
|
||||
|
||||
PQWidget QWidget_new();
|
||||
|
||||
void QWidget_show(PQWidget self);
|
||||
|
||||
PQPushButton QPushButton_new(const char* label, PQWidget parent);
|
||||
|
||||
void QPushButton_show(PQPushButton self);
|
||||
|
||||
int QApplication_exec(PQApplication self);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern C */
|
||||
#endif
|
Loading…
x
Reference in New Issue
Block a user