324 points · by c8g · 10y ago · 134 comments
Next time I want to build a desktop app I'll have a go with this for definite.
Then I remember that I'd be managing a custom heterogenous compute cluster just to compile some code.
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.
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?
In this case, you're depending on the Qt side (signal/slot management) to keep your lambda alive along with its entire call stack. But python doesn't know anything about QObject pointers, and will happily GC it. The next time that signal is fired, crash is extremely likely.
This used to be a much bigger problem in PyQt and PySide 4 and earlier, but it appears to have gotten better recently in PyQt at least.
In general, the best way to work with Qt is to let it assume control, and it use its mechanisms for lifecycle-management. I converted the code so that it used a QThread-derived Python class and QTimer. Works great.
You basically have to understand the Deep Magic that makes Python work under the hood, and ditto for Qt, too.
edit: can't comment any further currently, I will try to answer everything once I'm unblocked.
We've marked your account legit so it won't happen again. Welcome to HN!
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.
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.
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?
Sidenote: It's also possible to build Qt applications in Python using AsyncIO (using quamash), by integrating the Qt event loop as an AsyncIO event loop. This can be helpful to avoid race conditions, as much more interactions can be handled without thread concurrency.
I managed to use pyqt and autobahn|python (wamp protocol, RPC and pub/sub) in the same app thanks to quamash.
I set up an example app here https://github.com/icefo/PyQt5-Wamp
I've fixed crashes by keeping stuff assigned to variables to keep it from being GCed.
[0]https://m.reddit.com/r/golang/comments/585rvs/comment/d8xtre...
8GB RAM is rather optimistic.
edit: can't comment any further currently, I will try to answer everything once I'm unblocked.
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.
And it's a bit of a misconception that LGPL requires statically linked things to be open sourced: in that area it only requires that the LGPL components be replaceable (and the source for the LGPL components be available). In the context of static linking, that can be done by releasing pre-link binaries (object files) with instructions for linking them.
Of course, that's likely more work than just making the source available under a proprietary license (ie: provide source code so LGPL components can be replaced).
If you're using Qt GPL components, then yes, you'll need to open source your application (or pay for a Qt License)
edit: can't comment any further currently, I will try to answer everything once I'm unblocked.
Some of the language bindings that aren't maintained by Digia are still GPL, though. An example of this is PyQt, and the PyQt team's intransigence on the GPL is why PySide exists.
QT is Apple QuickTime which some consider as the worst Windows software ever created.
I was guilty of mispronouncing it too, until Qt 4 came out and they released that goofy "Qt 4 dance" video.
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.
I raised two small issues, and both were addressed quickly by the author. In one case incredibly quickly.
edit: can't comment any further currently, I will try to answer everything once I'm unblocked.
edit: can't comment any further currently, I will try to answer everything once I'm unblocked.
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?
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.
The demo application works without any of the libs from the deploy folder, but thats probably because it uses the system libs.
So cool:
- Option 1: 'go build' creates one large 50mb binary
- Option 2: 'qtdeploy' creates a bundle with a little more than whats required but you can remove what you dont need
- Option 3: just takes the binary and let the system provide the libs
Super cool would be, if that downsizing could be made automatically but since that icu stuff takes alone 24mb, that might be difficult. Anyway, great work. Spend half a day to get it working with system libs, but in the end I had to learn to just follow the tutorial and download qt again.
Great job :-)
I should probably mention that Option 1 is still depending on all the system/dynamic libs. And therefore only usefull to save time during development or if you need more control about the build. If you want to get a smaller binary, run `qtminimal` and `go build/run -tags=minimal` to include only the necessary C++ code, but the binary will still depend on the dynamic/system libs. I will add full statically linking in the future, but probably only after Qt 5.8 is released.
It looks like a tiny Windows 95 on your phone. Tap targets way too small.
[1] https://itunes.apple.com/de/app/auto-motor-und-sport/id36644... [2] https://itunes.apple.com/us/app/mens-health-fitness-trainer/...
Granted, I wish I didn't have to use JS with it, but QML itself is fantastic.
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?)
We detached this comment from https://news.ycombinator.com/item?id=12932238 and marked it off-topic.