Qt5 bindings for Crystal
Bindings for the Qt5 Framework using bindgen.
Table of Contents
- Project Goals
- User perspective
- Developer perspective
- Platform Support
- Just Works™ - Drop the dependency into a project, and use it
- Providing an API that feels native to Crystal
- Focus on the GUI components (i.e.
If you just want to develop a Crystal app which uses Qt5, use the
master-ready-to-use branch. It contains pre-built/pre-generated bindings for certain platform and Qt combinations. If that branch contains the pre-generated bindings for your platform, which you can verify in the subdirectory
ext/, you won't need bindgen at all.
dependencies: qt5: github: Papierkorb/qt5.cr branch: master-ready-to-use
If you want the bindings to be generated for the current system, or if you want to generate bindings for new platform and Qt combinations, use the master branch:
dependencies: qt5: github: Papierkorb/qt5.cr branch: master
In any case, your users will be required to have the Qt5 libraries on their system because this project defaults to binding to Qt libraries dynamically. (See more on this under License below.)
Additional development dependencies
Using your system's package manager:
pacman -S qt5-base
apt-get install qtbase5-dev
apt-get install qtbase5-dev
Sample Crystal-Qt5 code
Have a look in samples/!
A short Hello World snippet looks like this:
require "qt5" qApp = Qt::Application.new label = Qt::Label.new "Hello from Crystal/Qt!" label.show Qt::Application.exec
Generating the bindings
If you want to work on
qt5.cr itself or you want to generate bindings for new versions, then as mentioned you need to use branch
master and run the generation yourself.
These steps can be followed from a project using
qt5.cr, or from within
qt5.cr itself. For the latter, you can just go to
lib/bindgen and do
git checkout master instead of modifying
Important: For this you'll also have to meet the dependencies of bindgen.
qt5.cr supports many different versions of Qt on different platforms, generated bindings follow a naming scheme. The scheme contains 4 components as follows:
KERNEL - LIB_C - ARCH - qtVERSION, e.g.
KERNELis the OS kernel, e.g.
LIB_Cis the lib C name, e.g.
ARCHis the architecture, e.g.
VERSIONis the Qt version, e.g.
The naming scheme is not strictly enforced. However, it should always end with
(Re)generating all Qt5 binding versions
master-ready-to-use branch contains a number of prebuilt bindings. The following process was used to build them:
- Cd into the
qt5.crdirectory, switch to the master branch
support/generate_bindings.crand enable all versions for which you want to generate the bindings
- Commit the files in
The build process will automatically download, unpack, build, and generate all configured versions of Qt5. It'll store the downloaded and unpacked Qt5 versions to directory called
download_cache/. Subsequent invocations of that script will use these cached assets.
The first run may take a long time, and each version of Qt5 will take up about 4GB of disk space.
(Re)generating a specific Qt5 binding version
- Use the
- Decide which version of Qt to use, and build the scheme (See above)
- Export the binding scheme:
- If you're not using your system's Qt:
- Run bindgen as usual:
lib/bindgen/tool.sh qt.yml --stats
- Verify with
Future things to do
qHash()of wrapped types (to
- Integration with LibEvent: Right now, Qt blocks the whole thread.
- The rest of the billion Qt classes of interest
- Everything in the to be done category
- Integration for the
Qt DesignerUI designer
- Integration for
- Localization/Translation for your applications!
- UI test library, with adapter for
- Also, actual tests - Let's catch whacko bugs right in the CI!
- Automated copy (and adaption) of the Qt documentation, for easy Crystal-specific docs
- The Qt Docs license should allow this if done correctly
|Other systems||Help wanted||?||?|
Ready-to-use Qt versions: 5.5 to 5.12
(This list needs updating)
- Open a new issue on the project to discuss what you're going to do and possibly receive comments
- Read bindgen's
STYLEGUIDE.mdfor some tips
- Then do the rest, PR and all. You know the drill :)
- Papierkorb Stefan Merettig - creator
The Qt bindings, including the generated and manually-written parts, are subject to the MPL-2 license. You can find a copy attached of the full license text in the
This project claims no copyright on the
Qt framework or of any of its trademarks, source, or any other assets.
A note on Qt's license
A common misconception is that you have to pay for Qt to use it in closed-source applications.
This project assumes you'll link to Qt dynamically. In this case, you can use Qt free of charge including for closed-source, commercial applications under the terms of the LGPL.
You can build closed-source applications using Crystal, this shard, and Qt for free.
Note: This section is to combat this misconception, the authors of
qt5.cr are in no way responsible to check if the same terms apply in your jurisdiction.
- 15 days ago
- August 22, 2017
Mozilla Public License 2.0
Tue, 20 Apr 2021 07:58:10 GMT