therecipe / qt

Qt binding for Go (Golang) with support for Windows / macOS / Linux / FreeBSD / Android / iOS / Sailfish OS / Raspberry Pi / AsteroidOS / Ubuntu Touch / JavaScript / WebAssembly
GNU Lesser General Public License v3.0
10.48k stars 748 forks source link

qtdeploy not including the libraries properly while building subpackages #1008

Open paboum opened 5 years ago

paboum commented 5 years ago

I'm quite new to Go in general so this could be totally wrong, but having the following code:

###
./fancy/fancy.go:
package fancy

import (
    widgets "github.com/therecipe/qt/widgets"
)

func Print(s string, w *widgets.QPlainTextEdit) {
    w.AppendPlainText(s)
}

###
./main.go:
package main

import (
    "./fancy"
)
...
fancy.Print("test")

results in:

fancy/fancy.go:8:3: w.AppendPlainText undefined (type *widgets.QPlainTextEdit has no field or method AppendPlainText)

When I move this file back to main package, it works fine.

The experiments I made lead me to the conclusion that while the "." package is built correctly, the dependencies are assumed to work without Qt imports, which is false in larger projects.

therecipe commented 5 years ago

Hey

I think the problem is the relative import, while using relative imports seem to work with go run or go build, they can cause issues when using something like go list (which is used internally by qtdeploy to detect dependencies).

To solve this, you just need to use a "normal" import, such as myproject/fancy where the fancy folder is located in $(go env GOPATH)/src/myproject/fancy for example.

I can look into the relative import issue again, but IIRC then I wanted to supported them but couldn't due to the way go list works. Or maybe it was possible to supported them, but it would have come with quite a lot of overhead, I can't really recall it.