go-qml / qml

QML support for the Go language
Other
1.96k stars 189 forks source link

Hack to enable imgprovider to run from any directory. #52

Closed RickyS closed 10 years ago

RickyS commented 10 years ago

To test the ability of imgprovider to use the embedded image, I ran it from my home directory, where it complained that it could not load the qml file. I've rashly put together a reasonable hack to fix that, by having the program change working directory to the directory where the binary executable resides, in the hope that the qml file will be there. It works, but...

I now realize that this defeats the purpose of the example, which I understand to be using the image embedded in the executable. Feel free to incorporate this. But I think I should research how the qml file could instead be embedded in the runtime binary. Do you know how to do this?

niemeyer commented 10 years ago

The QML file can be embedded in the binary by loading it from a string. See the snapweb example for an idea:

https://github.com/go-qml/qml/blob/0e892b1a/examples/snapweb/snapweb.go

Regarding the change, a better way to do that in a real application would be to simply os.Open the file from whatever directory the image is in, instead of moving the current process there. But you're right, this is just an example that shows how ot use an image provider, so we seem good about that for the moment.

Thanks for the suggestion, even then.