
Qt binding for Go with support for all major operating systems - c8g
https://github.com/therecipe/qt
======
nickcw
I love that the author provides docker images for cross compilation. Cross
compilation environments are such a pain to setup and maintain - having docker
images with all that stuff in is a major step forward.

Next time I want to build a desktop app I'll have a go with this for definite.

~~~
herge
Docker will only let you cross-compile to OSes with the same kernel, which is
relatively limited. A full set of say vagrant files would be slower, but a lot
more polyvalent (but even then it would not let you, say, compile a windows
binary from linux).

~~~
detaro
You can _cross_ -compile to completely different environments. It just can be
tricky to set up, so prepared docker images with e.g. the toolchain to build a
Windows executable on Linux are great to have, and what is provided here.

~~~
cryptarch
I think it's a nice idea in theory to provide cross-compilation support by
means of emulating all possible target architectures on the compiling machine.

Then I remember that I'd be managing a custom heterogenous compute cluster
just to compile some code.

~~~
mentat
It's not emulation, it's cross-compilation which has existed basically
forever. You don't have to target the same instruction set as the one you're
compiling on.

~~~
cryptarch
I am well aware of that, I was referencing the concept of "cross-compilation"
the GP seemed to have.

~~~
mentat
I see what you mean now, using like qemu or something. So "emulated native
compilation". It is an interesting concept. Sorry for misunderstanding you.

~~~
cryptarch
Indeed, "virtualbox-the-crosscompiler" (probably from hell). QEMU would be a
few orders of magnitude slower but I think it supports many more archs.

No hard feelings :)

------
zemo
I wish the author success. Many UI libraries for Go have been made and
abandoned. It would be a joy to see one succeed.

~~~
StavrosK
Not only a joy, it would be the best way we currently have to make desktop
applications. Currently the easiest alternative is JS+Electron, but that's
just horrible because of all the waste of resources. Python is hard to
package, so something statically compiled would be great.

I would prefer Rust for this (or, well, I would prefer Python with a better
packaging story), but Go is much better than the alternatives too.

~~~
jdc0589
python can be packaged up. I haven't done it, but there are some popular 100%
python apps with a UI that dint require any global python crap.

~~~
jonwayne
Like Sublime.

~~~
nawariata
Sublime Text is mostly written in C++, Python is only used for plugin API.

------
friendzis
Serious question:

Once I have been building Qt Widgets application in Python with PySide
bindings. I needed to do some simple processing in several SLOTs and decided
to use lambdas as an easy replacement. Kids, do not even think about
attempting to do this at home, seriously.

I have run into some extremely evasive random crashes and stuff. I did not dig
to the bottom of the issue, although my guess is that Python lambdas are
executed in main (constructing) thread context and that causes race
conditions.

My question: how do Golang's goroutines interact with native threads spawned
by Qt?

~~~
ffjffsfr
I have some experience building PyQt apps and can confirm random crashes
(segfaults, sigaborts and such). I suspect this has nothing to do with
lambdas. It may likely be something happening between Python and QT - remember
that all things happening in QT/C++ world are invisible to Python. For example
if your Python routine returns None (as many Python methods, functions do)
instead of some other object that is expected by C++ (say QNetworkRequest) it
may crash and die without any traceback. I spend hours on things like this -
QT method must return something but in some cases was not returning expected
object and whole thing was crashing. Python being Python doesn't care about
return types, there is no Python traceback, you're left in the dark groping,
browsing codebase trying to find what might get wrong, no debugger will help
you.

Working with QT bindings is very difficult. Debuging things is not easy. I'm
not sure if using bindings is worth it. I suspect doing things in plain C++ QT
might be easier to debug and maintain.

~~~
blub
In C++ one gets a compilation error if the wrong type is returned from a
function.

Qt is generally type safe, but it uses quite a lot of pointer types and also a
rather unusual for C++ parent-child resource cleanup rule for QObjects (e.g.
all widgets).

When something does crash, C++ doesn't offer any tracebacks, but if one has a
core dump or can reproduce the crash under a debugger, a traceback can be
easily obtained in the majority of cases.

~~~
ffjffsfr
> but if one has a core dump or can reproduce the crash under a debugger, a
> traceback can be easily obtained in the majority of cases.

how do you create core dump? starting program under some debugger? I tried
debugging with valgrind but the output contained so much noise it took my ages
to find something. I also had to recompile QT used by PyQT because QT because
QT requires some flags to be able to debug. What's the best way to debug
things like this?

~~~
blub
A core dump is a file that's generated by the OS and includes a snapshot of
the process state. It's useful when e.g. one is not able to run the program
under a debugger. Enabling it depends on the OS, I would just search for
enable core dumps on "my OS".

If one _can_ run the target program under a debugger, a core dump is not so
helpful because it's a static snapshot, whereas a debugger can modify program
state.

I am guessing that one has to run the python process itself under the debugger
and pass the parameters such as the script path.

There will probably be a signal or exception condition at one point and one
can take a look at the call stack. The call stack will probably be messy, as
it will include python internals.

An alternative way to debug this is to understand the lifetimes and
preconditions of C++ widgets and signals and slots and review one's python
code.

Unless there's a bug in Qt itself, PyQt and Qt might have a misunderstanding
about lifetimes and something gets cleaned up too soon or there's a dangling
refrence to a cleaned up object

~~~
dom0
There is a gdb plugin for Python. I'm not sure how other distros handle it,
but on Arch Linux you _have_ to build Python yourself for it to work.

------
cjslep
So this is more comprehensive than the qml binding library?[0]

[0][https://github.com/go-qml/qml](https://github.com/go-qml/qml)

~~~
c8g
The Author said about go-qml and this binding in reddit[0]

[0][https://m.reddit.com/r/golang/comments/585rvs/comment/d8xtre...](https://m.reddit.com/r/golang/comments/585rvs/comment/d8xtrez)

------
transfire
The code has a mind boggling LOC. e.g.
[https://github.com/therecipe/qt/blob/master/widgets/widgets....](https://github.com/therecipe/qt/blob/master/widgets/widgets.go)

------
oblio
Now if only someone did the same thing for .NET Core. Ideally someone who
would want to build a business on that :)

~~~
elcct
You mean Go bindings for .NET Core?

~~~
oblio
.NET Core bindings for Qt. .NET Core doesn't have any UI toolkit right now.
There are several efforts but they're mostly hobbyist ones and seem to lack
funding or major development power, unfortunately.

~~~
elcct
What about WPF?

~~~
0xCMP
It's not designed to do cross platform UIs and QT already is. It's be easier
to bind QT to .NET than make WPF cross platform.

------
dekhn
Does this library support making "derived classes" from QObject/QWidget? And
how does that work, in Go- are they interfaces?

~~~
therecipe
author here; Yes, you can create derived classes from any class that is
derived from QObject. Simple anonymously subclass in Go and add your own
slots/signals, as shown in the "quick/bridge" and several other examples. Then
run "qtmoc" to generate the need c++ and go code. All functions usually accept
interfaces and all classes have their corresponding interface, which itself
inherits all the derived interfaces.

~~~
dekhn
That's great!

------
nisdec
Could someone please enlighten me why an installation would need 8gb of free
ram?

~~~
oblio
If it's building everything (including Qt), Qt includes Webkit. I imagine
that's a lot of C++ code to build.

~~~
creshal
QtWebkit _and_ QWebEngine, which uses Blink(/CEF).

8GB RAM is rather optimistic.

------
MayeulC
I am wondering if there is something similar for Rust. Does anyone have some
information on this?

~~~
deutronium
Not Qt, but I'm using [https://github.com/gtk-rs/](https://github.com/gtk-rs/)
with Rust, which is pretty cool, I've developed the GUI using Glade, which I
load via Rust. I'm also using CSS, to style the interface.

~~~
weberc2
Unfortunately GTK itself is pretty bad, and it constantly has breaking
changes. Hopefully things are improving.

------
johnhattan
Question. Does QT still have a licensing problem for closed-source apps on
mobile platforms?

Last I saw, QT's GPL/LGPL license required you to open-source the code that
was statically linked to it. That wasn't much of a problem for desktop
platforms, as you could just package up all of QT into its own QT.DLL (or the
equivalent) and link to it dynamically. But this isn't allowed on stuff like
iOS, so you were required to buy a license for those.

~~~
pawadu
nitpick: its Qt, not QT.

QT is Apple QuickTime which some consider as the worst Windows software ever
created.

~~~
amyjess
Adding to that, "Qt" is pronounced like "cute", while "QT" is pronounced like
"cutie" (though with different stress).

I was guilty of mispronouncing it too, until Qt 4 came out and they released
that goofy "Qt 4 dance" video.

------
bobwaycott
Why do the iOS screenshots look nothing like iOS?
[https://github.com/therecipe/qt/blob/master/internal/screens...](https://github.com/therecipe/qt/blob/master/internal/screenshots/ios_portrait.png)

~~~
bluehazed
It's the Qt framework, not iOS's UI framework.

~~~
maemre
It definitely looks like Qt but I am surprised that Qt is not using any native
controls on iOS. It tries to use native controls or at least a native _look
and feel_ if possible (it does so on Windows and macOS at least). On the other
hand, I don't know anything about mobile app development and apis that iOS
gives you so I cannot tell whether such a thing is possible in iOS at all.

~~~
distances
Two points:

a) Qt doesn't use native controls on any platforms (though for half of desktop
Linuxes Qt _is_ the native toolkit). Qt has its own controls that are styled
to look like native.

b) The screenshot shows Qt widgets. This is not the intended way to do Qt on
mobile platforms, and thus no native styling is provided. QML is the official
way to do mobile apps with Qt.

~~~
72deluxe
Point A is interesting because you can see particularly on OSX that it is not
native, despite widespread recommendations to use Qt for cross platform
development. I have used wxWidgets on multiple platforms and despite its
idiosyncrasies, I have found it performed very well and is obviously truly
native on all platforms (unless you choose wxUniversal as a rendered; nobody
does) or unless you do "owner drawn" stuff and paint yourself. In any case I
would not hesitate recommending wxWidgets for native controls over Qt.

Other minor Qt annoyances include their own scrollbars which ignore the system
setting of "jump to where I click the thumb" setting etc.

------
pekim
I've been using this library for a couple of weeks, and so far I have been
very impressed. It's relatively easy to use, and seems to be pretty
comprehensive in the amount of the Qt API that it supports.

I raised two small issues, and both were addressed quickly by the author. In
one case incredibly quickly.

------
tachion
Sadly, FreeBSD is not included in the supported OS list.

~~~
therecipe
author here; Didn't know it was supported by Qt, I will put it on my TODO list
;)

edit: can't comment any further currently, I will try to answer everything
once I'm unblocked.

------
jscheel
This is awesome. I was really bummed about the state of QT support in golang.
I played with the go-qml project, but it wasn;t everything I needed. This
looks amazing.

------
dharma1
Does this support QML/Qt Quick Controls 2?

~~~
therecipe
author here; Yes, as well as material design and all the stuff that comes with
QML/Qt Quick.

------
xmichael99
Please, please where is a proper C# binding?

------
andrewfromx
big fan of the repo
[http://github.com/dontpanic92/wxGo/](http://github.com/dontpanic92/wxGo/)
it's got everything Qt has but free

~~~
chrisper
Is Qt not free?

~~~
andrewfromx
Commercial licensing $79/month [https://www.qt.io/licensing-
comparison/](https://www.qt.io/licensing-comparison/)
[https://www.qt.io/faq/#_Toc_2](https://www.qt.io/faq/#_Toc_2)

------
Siecje
Is there an example of using data from Go in the application?

~~~
therecipe
author here; Take a look inside the `internal/examples` subfolder. There are
several examples.

edit: can't comment any further currently, I will try to answer everything
once I'm unblocked.

------
JepZ
Does anybody know why the demo application is 52mb?!?

I mean, yes, its statically linked but 52 million bytes for a window, a button
and a pop-up?

Shouldn't this fit into 5-10 mb? Is the whole qt lib linked into that binary?

~~~
therecipe
author here; The size depends on your platform and the way you build it. If
you used `qtdeploy` instead of `go run/build`, you should get a 2mb binary
which includes Go's runtime + only the needed Qt C++ code. (A normal go binary
has the size of 1.5mb or so) The rest are Qt dynamic libs, which are not all
needed, depending on what you build. You can safely remove plugins and maybe
whole modules. edit: and you can also compile Qt on your own to strip out ICU
and other unnecessary stuff + with Qt 5.8 things will get even more
lightweight.

~~~
bostik
First of all, thank you. The effort of maintaining Qt in any way or form is
... nontrivial.

I've wanted to try this one out, but it looks like I'm maybe trying something
too far off from mainstream. I like how the bindings can be built against
incomplete Qt releases (iow. just the development packages available in debian
sid); the build complains when some modules can't be found but continues
nonetheless. Sure, it takes QT_DIR and PKG_CONFIG settings to build like this
but I have no problem there.

So far I haven't found a way to build even the sample project against this
type of custom build though. I'll try to find more time to dive in as to why
this happens but I'm sure this is an error on my end. Once I figure that out,
I should be able to provide a documentation update.

As to why? I have an old project which I need to revive, and being stuck in
ancient GTK land with dubious bindings and even more dubious upstream
practices sounds less appealing than porting things over.

~~~
therecipe
Did you tried to use QT_MISC_DIR (which should contains the "mkspecs"
subfolder) and QT_DOC_DIR, which should contain for example
(QtCore/qtcore.index)? Or if you like, open an issue on github and we can try
to sort this out :) edit: also if you use PKG_CONFIG=true, the QT_DIR will be
ignored

~~~
bostik
Hum, I hadn't, but in retrospect I should have. I've done my share of Qt
builds in the past and mkspecs path was often an amusing detail. Didn't solve
the problem though.

But I think I found out at least one thing that goes wrong. I'll provide a
github issue report later this weekend but here's the short version:

* The generated #cgo directives for CXXFLAGS are different for desktop and minimal files. Minimal is generated with -I$(QT_INCLUDE_DIR)/QtFoo include paths; desktop is generated with -I$(QT_DIR)/<major.minor>/gcc_64/include/QtFoo paths instead. So headers in desktop build are looked up from _library_ directory paths (and with obviously bad path elements too).

* When building, qtsetup goes for desktop target.

More data coming in via github once I get the exact details sorted out.

~~~
therecipe
Mh, usually the minimal_cgo_* files and the cgo_* files should use the same
imports.

But the qtsetup won't always re-generate these cgo_* files if the QT_DIR is up
to date (there is probably a bug if you use QT_PKG_CONFIG).

So I would use `qtminimal` or `qtdeploy` for debugging this, because the
minimal_cgo_* files are always re-generate.

And you may also want to change `InfoLevel` in `internal/utils/logger.go` to
`DebugLevel` and then re-build the cmd/tools to get additional infos.

Hope this helps :)

------
nardi
Please, I beg of you, do not create an iOS app using this library. Look at
that screenshot:
[https://github.com/therecipe/qt/blob/master/internal/screens...](https://github.com/therecipe/qt/blob/master/internal/screenshots/ios_portrait.png)

It looks like a tiny Windows 95 on your phone. Tap targets way too small.

~~~
zerr
That's because it is done with Qt Widgets. "Proper" way for mobile is to use
Qt Quick Controls, but you have to deal with QML/js crap unfortunately.

~~~
dkersten
QML isn't crap. Its much nicer, IMHO, than HTML and CSS and much more
intuitive. The animation and states system makes it trivial to make polished
looking UI's.

Granted, I wish I didn't have to use JS with it, but QML itself is fantastic.

~~~
zerr
Of course, when I say it's crap, I mean compared to C++/Qt Widgets. I wish
Quick Controls were available in pure C++.

~~~
dkersten
You can use them from C++, but its definitely not the expected usage and not
particularly easy.

I personally much prefer QtQuick to QtWidgets, and really like the QML
declarative language as a better HTML/CSS for non-web. But I completely agree
with you that I would prefer if I could code all my logic in C++ and not JS.

I've been meaning to play around with two ideas:

1\. Construct the QtQick widget scenegraph wholly from C++ (and not using
QML/JS at all). Doable, but definitely not intended usecase.

2\. Construct the scenegraph using QML, but using it only for setting values
(and never any logic) and then manually connecting the signals from the QML-
created widgets to C++ slots.

~~~
enqk
It is not wise to even implement a lot of logic in the JS part of QML, as the
JS interpreter there is quite a bit more primitive than something like V8.
Your performance will suffer if you attempt to write anything too complicated
in JS inside QML.

~~~
dkersten
Oh I know, I've had some complex QML/JS in the past.

Even more so if you're running on iOS where the JS isn't jitted.

It's really easy to write QObjects that are accessible to QML and you can
connect your signals/slots with the QML widget ones, so having the logic in
C++ isn't hard. It's just not quite as convenient as putting it inline in QML,
I guess.

------
xmichael99
Where is the proper useful C# binding....

------
amelius
Does Qt have something like React?

~~~
hellofunk
QML does provide an FRP-like methodology, which is not exactly like React but
in the same universe of UI techniques.

------
kuschku
So, dang, why is my account rate limited then? I’ve had 2 cases before where a
project I participated in was presented here, and I showed up to comment, and
couldn’t do so due to the rate limiting.

This is not really helpful, and destroys any chance at meaningful discussion.

(Also, last time you told me that rate limiting couldn’t be undone, and I
should just write an email – what’s that about now?)

~~~
dang
There are other reasons for rate-limiting besides an account being new—if an
account has posted a lot of unsubstantive or uncivil comments, for example. I
doubt that I told you it couldn't be undone, because it can be undone. What I
probably said was that you should email us because it isn't a good idea to go
on about it here.

We detached this comment from
[https://news.ycombinator.com/item?id=12932238](https://news.ycombinator.com/item?id=12932238)
and marked it off-topic.

------
blowski
Please change the title - the long string breaks the HN layout on my phone.

~~~
ldev
Please add (2016) to the title.

