Skip to content
Snippets Groups Projects
Commit 9d62d5e3 authored by jkito's avatar jkito :skull: Committed by Pea Nut
Browse files

qt: pass char * to go functions from cpp helpers

instead of converting QString to GoString struct which is
error prone, this changes SetTransport and UseLocation in
backend.go to receive a char* as arg, which is  converted
to Go string using the C.GoString helper

this fixes a bug on macOS where changing preference options
did not have any effect as the conversion of string was not
working and empty values were passed to Go functions
parent 83f5933c
Branches
Tags
1 merge request!223qt: pass char * to go functions from cpp helpers
......@@ -31,10 +31,8 @@ func SwitchOff() {
}
//export UseLocation
func UseLocation(label string) {
// a bit of a hack to force the compiler to copy the string
// so the original C++ string will not be used as it will be changed down the line
location := string([]byte(label))
func UseLocation(label *C.char) {
location := C.GoString(label)
backend.UseLocation(location)
}
......@@ -44,8 +42,9 @@ func UseAutomaticGateway() {
}
//export SetTransport
func SetTransport(transport string) {
backend.SetTransport(string(transport))
func SetTransport(transport *C.char) {
tp := C.GoString(transport)
backend.SetTransport(tp)
}
//export GetTransport
......
......@@ -48,7 +48,10 @@ void Backend::donateSeen()
void Backend::useLocation(QString label)
{
UseLocation(toGoStr(label));
QByteArray loc = label.toUtf8();
char *c = loc.data();
UseLocation(c);
}
void Backend::useAutomaticGateway()
......@@ -58,7 +61,10 @@ void Backend::useAutomaticGateway()
void Backend::setTransport(QString transport)
{
SetTransport(toGoStr(transport));
QByteArray tp = transport.toUtf8();
char *c = tp.data();
SetTransport(c);
}
void Backend::setUDP(bool udp)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment