[ANN] (GUI) Qt binding which supports Windows / macOS / Linux / Android / iOS / Sailfish OS / Raspberry Pi

963 views
Skip to first unread message

the_r...@hotmail.com

unread,
Nov 10, 2016, 3:34:36 PM11/10/16
to golang-nuts
Hey everyone,

I would like to officially announce the project I'm working on for a while now.
It's a binding for the Qt framework + some tools to help you with development and deployment of your Qt applications.

The most interesting feature of the Qt framework for the Go community is probably that it can be used to develop native looking GUI applications for various platforms without the need to make platform specific changes to your code.
Beside the GUI modules Qt also includes: a webengine (chromium), several multimedia functions, access to bluetooth + nfc, access to various hardware sensors, gamepad support, access to position informations and much more ...
The Qt article on wikipedia: https://en.wikipedia.org/wiki/Qt_(software)


There are two caveats for those who intent to use the binding:

1. You code won't be pure Go anymore, as this binding heavily relies on cgo.
2. The binding dynamically links to Qt's libraries, which results in 25-50mb (depending on the platform) uncompressed libs that have to be deployed along with you binary.
(But it's also possible to link against the static Qt libs and remove this need. And there is also work being done to reduce the size of the dynamic libs in the upcoming versions of Qt.)


For the pro side, I should probably mention that:

1. The deployment to most platforms is pretty trivial (that includes cross compiling). (And there will be even more supported platforms in the future)
2. That the binding is almost complete and already supports most Qt modules (30+).
3. There are a lot of examples to get you started. (And porting over existing C++ examples should be super simple)


If someone is interested in testing it out, it can be found here:


Or if you just want to take a quick look and test the examples on Linux and you are familiar with Docker.
You could use one of the images as well: `docker pull therecipe/qt:base`
And simply run `qtdeploy build desktop` in one of the `$GOPATH/src/github.com/therecipe/qt/internal/examples/` sub-sub folders. (inside the container)
There will be a new folder created called `deploy`, which should contain everything that is needed to run the application on a regular 64-bit Linux system.


Please let me know what you think.
Any feedback is welcome :)

Rusco

unread,
Nov 10, 2016, 5:42:41 PM11/10/16
to golang-nuts
Good to see some progress on the GUI front - I think you are up to something !
Rusco

therecipe

unread,
Nov 11, 2016, 4:38:23 PM11/11/16
to golang-nuts
Thank you, I appreciate it :)

Tong Sun

unread,
Nov 11, 2016, 9:49:14 PM11/11/16
to golang-nuts
Cool! 

Does it support the declarative QML

Jason Stillwell

unread,
Nov 12, 2016, 11:55:48 AM11/12/16
to golang-nuts
I gave it a try using QMdiArea. It seems to work well.

But I'm confused about where the errors go. There doesnt' seem to be a way to check for errors. Does it panic in every error situation?

therecipe

unread,
Nov 12, 2016, 12:36:27 PM11/12/16
to golang-nuts
Yes it's fully supported, you might want to take a look at the `internal/examples/qml` or `quick` folder.
To see how you can interact with QML from Go.

Pietro Gagliardi

unread,
Nov 12, 2016, 12:54:16 PM11/12/16
to Jason Stillwell, golang-nuts
Does Qt even expose errors itself? Back when I did Qt I never had to check myself...

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

therecipe

unread,
Nov 12, 2016, 1:36:12 PM11/12/16
to golang-nuts
As Qt itself doesn't use exceptions (even through it partially supports them), there are no Go like error returns.
Instead if something unexpected happens, most classes provide functions to receive an error message or error code in some way.
So it will only panic if something happens, that's impossible to recover from.

therecipe

unread,
Nov 12, 2016, 1:47:24 PM11/12/16
to golang-nuts, drag...@gmail.com
Most times there is some function that returns either some error code or some error string.
Like in http://doc.qt.io/qt-5/qmediaplayer.html#error, but it's rarely needed.

Justin Israel

unread,
Nov 12, 2016, 2:36:15 PM11/12/16
to therecipe, golang-nuts, drag...@gmail.com


On Sun, Nov 13, 2016, 7:47 AM therecipe <the_r...@hotmail.com> wrote:
Most times there is some function that returns either some error code or some error string.
Like in http://doc.qt.io/qt-5/qmediaplayer.html#error, but it's rarely needed.

Am Samstag, 12. November 2016 18:54:16 UTC+1 schrieb Pietro Gagliardi (andlabs):
Does Qt even expose errors itself? Back when I did Qt I never had to check myself..

That,  or objects will have validation methods on them like isValid(), isNull(), isEmpty(), with documentation about when to expect those conditions. 

QRegExp also happens to expose an errorString() method, as an example of a case where it needs to communicate more information:

Jason Stillwell

unread,
Nov 13, 2016, 1:12:52 AM11/13/16
to Justin Israel, therecipe, golang-nuts

Those are great answers. Not having used qt before, I needed this help. Thanks.

Rich

unread,
Nov 13, 2016, 7:30:58 PM11/13/16
to golang-nuts
This looks very well done. I've not done any real programming in it but looking over the github it looks like this is well on it's way.  Thank you!! i have a few programs I've been meaning to write that needed a gui, I'll be giving this a shot.



On Thursday, November 10, 2016 at 3:34:36 PM UTC-5, therecipe wrote:

gerald...@gmail.com

unread,
Nov 15, 2016, 5:47:41 AM11/15/16
to golang-nuts
Great news! is it possible to load the gui which has been created with qt creator? 
is there anything which you still plan to add/extend?

Justin Israel

unread,
Nov 15, 2016, 1:21:53 PM11/15/16
to gerald...@gmail.com, golang-nuts


On Tue, Nov 15, 2016, 11:47 PM <gerald...@gmail.com> wrote:
Great news! is it possible to load the gui which has been created with qt creator? 

I doubt it. That would require converting your Go code into a Qt .ui file format, which I would be surprised if the library supported. Then for it to be useful it would also have to have the equivalent of pyuic (for PyQt4, or pyside-uic) to convert from a UI file back to Go. 

Seems more likely that UI code will just be designed by hand. 

--

therecipe

unread,
Nov 15, 2016, 7:12:39 PM11/15/16
to golang-nuts, gerald...@gmail.com
Converting Go code to ui xml is not supported and currently not planned.
But you can load ui files created by the Qt Designer with the help of the uitools pkg, you might want to take a look at the basic example in internal/examples/uitools.
I'm planning to port the uic application to convert ui files to Go code in the future, but haven't really looked into that yet.

Also there are a lot of small additions planned, but nothing big beside new supported platforms and Qt 5.8.
I will instead cleanup the code and work on the usability of the tools.

howar...@gmail.com

unread,
Nov 15, 2016, 7:53:08 PM11/15/16
to golang-nuts
therecipe, is there a means available to render image.Image or draw.Image (go Image) objects to Qt images/buffers/etc?

I was not able to locate such a facility in several other libraries. In the end I got fed up and wrote my own for converting a draw.Image to a GdkPixBuf to get gtk2 and gotk3 working. Is there a similar raw in-memory image format for Qt that is accessible in a way I could manually create it from an image.Image? (In other words, one where the raw bytes are accessible for setting, as an array, etc?)

Howad

therecipe

unread,
Nov 15, 2016, 8:42:58 PM11/15/16
to golang-nuts, howar...@gmail.com
Yes, you could encode the image.Image to []byte (in png or some other image format) and use the encoded data to create a QByteArray, which then can be used to create a QImage.
The QImage can then be used to edit the image or to create a QPixmap, which can be displayed inside a QGraphicScene, QLabel, ...
I played around with something like that last week and created an example, maybe this is the part that interest you: https://github.com/therecipe/qt/blob/master/internal/examples/widgets/renderer/renderer.go#L145-L187

And here are some infos about the different classes that Qt provides to work with image data http://doc.qt.io/qt-5/qpixmap.html#details

howar...@gmail.com

unread,
Nov 17, 2016, 8:29:20 PM11/17/16
to golang-nuts, howar...@gmail.com
What version of QT is it intended to be built against? I get
therecipe/qt/core/core.cpp:9:30: fatal error: QAbstractAnimation: No such file or directory
when I try to build against it, or when trying to build the renderer example.

qt5-default says it is 5.5.1+dfsg-16ubuntu7.2 and qtdeclarative5-dev is 5.5.1-2ubuntu6

I am building on Ubuntu 16.04.1 LTS.

Howard

therecipe

unread,
Nov 18, 2016, 10:10:11 AM11/18/16
to golang-nuts, howar...@gmail.com
It's intended to be build against Qt 5.7.
And I think Qt 5.6.2 works also (with some errors/warnings during the setup)
I may add backward compatibility in the future, but it's not planned yet.

I use this script to get Qt 5.7 on trusty, if you want to link against system libs.

Otherwise I would recommend to try the official pre-build packages, which will also allow stand alone deployments of you application.
Reply all
Reply to author
Forward
0 new messages