随便写个QT窗口

将代码编译成库文件

Go中调用这个函数

完成

字符串参数传递
#include <QtGui>
extern "C" void qtDebug(const char *typeName)
{
qDebug() << "Debug:" << typeName;
}
extern "C" int start(const char *typeName) {
int argc =0;
char **argv = 0;
QApplication a(argc, argv);
QDialog w;
QLabel l(&w);
l.setText(typeName);
w.show();
return a.exec();
}
package main
/*
extern int start(const char *typeName);
extern void qtDebug(const char *typeName);
*/
// #include <stdio.h>
// #include <stdlib.h>
// #cgo LDFLAGS: -L./ -ldemo
import "C"
import "unsafe"
func main() {
cTypeName := C.CString("abc")
C.qtDebug(cTypeName)
C.start(cTypeName)
C.free(unsafe.Pointer(cTypeName))
}
近期评论