This project provides bindings that allow the QT Gui toolkit to be used from the Ruby Programming language. Overall it is a repackaging of a subset of the KDE bindings ruby and smoke systems into a format that lends itself well to packaging into a Ruby gem.
- To make it easy to install a Qt binding for Ruby on all platforms using RubyGems
- To maintain an up-to-date binary gem for Windows that is bundled with the latest version of Qt
- To reduce the scope and maintenance of the bindings to only bind to the libraries provided by the Qt SDK.
- To increase compatibility with non-linux platforms
Note: This gem supports Ruby 2.0.0+ starting at qtbindings version 220.127.116.11. For Ruby 1.9.3 you should use version 18.104.22.168. For Ruby 1.8.x you can try installing version 22.214.171.124, however upgrading Ruby is highly recommended.
Ruby threading is now fully supported out of the box. All GUI access however must be done inside the main thread. To support updating the GUI using other threads, use the following function provided in Qt4.rb:
Qt.execute_in_main_thread do # block the main thread # GUI code which executes and then allows the main thread to execute end Qt.execute_in_main_thread(false) do # don't block the main thread # GUI code which executes in parallel with the main thread end
To use Qt plugins (Reading jpgs, etc) on Windows, you should add this line after creating your Qt::Application.
Mac OSX 10.9.1 (Mavericks) XCode 5 (clang) Brew - QT 4.8.6 Cmake 2.8.9 Ruby 2.0.0p353 - Must be compiled with clang (rvm install --with-gcc=clang)
Windows XP SP3 QT SDK 4.8.5 Cmake 2.8.8 Ruby Ruby 2.0.0p481 installed from rubyinstaller.org
Windows 7 SP1 QT SDK 4.8.6 Cmake 126.96.36.199 Ruby 2.0.0p353 installed from rubyinstaller.org
Ubuntu Linux 11.10 QT SDK 4.8.1 Cmake 2.8.5
Compiling qtbindings requires the following prerequisites:
- cmake 2.8.x installed and in your path
- QT 4.8.x installed and in your path
- Ruby installed and in your path (Ruby must be compiled with --enable-shared on all platforms and with --with-gcc=clang on OSX)
- gcc 4.x (or clang for OSX 10.9) For Windows this means getting MingGW-w64 from http://mingw-w64.sourceforge.net/download.php (Win-builds project)
Note for OSX 10.9. The default compiler has changed from gcc to clang. All libraries need to be compiled with clang or you will get segfaults. This includes ruby, qt, and qtbindings. *** rvm does not compile with clang by default. You must add --with-gcc=clang when installing a version of ruby ***
Additionally: all of the operating system prequisites for compiling, window system development, opengl, etc must be installed.
Perform the following steps to build the gem on Unix or Mac:
rake VERSION=4.8.x.y gemWhere the x is the subversion of QT and y is the patch level of qtbindings
Perform the following steps to build the gem on Windows:
- Ensure you are running Ruby 2.0.0
ruby -v #=> ruby 2.0.0
- Switch to Ruby 2.1.3
ruby -v #=> ruby 2.1.3
rake VERSION=4.8.x.y gemnativeWhere the x is the subversion of QT and y is the patch level of qtbindings
rake VERSION=4.8.x.y gemqtWhere the x is the subversion of QT and y is the patch level of qtbindings
Note: The gem is built twice to create the FAT binary which will work on both Ruby 2.0 and 2.1. The Windows utility called pik is useful for switching between Ruby versions.
After building the gem, verify the examples work by running:
Operating Systems Notes:
- The following should get you the packages you need:
sudo aptitude install build-essential bison openssl libreadline5 libreadline-dev curl git-core zlib1g zlib1g-dev libssl-dev vim libsqlite3-0 libsqlite3-dev sqlite3 libxml2-dev git-core subversion autoconf xorg-dev libgl1-mesa-dev libglu1-mesa-dev
You will also need these packages:
sudo yum install qtwebkit-devel qtwebkit
Mac OSX Snow Leopard
- Brew (http://mxcl.github.com/homebrew/)
Install qt with
brew install qt
Windows - Note: Only necessary for debugging (binary gem available)
QT 4.8.6 requires mingw 4.8.2 from http://mingw-w64.sourceforge.net/download.php (Win-builds project) QT 4.8.5 requires mingw 4.4 from here or elsewhere: http://nosymbolfound.blogspot.com/2012/12/since-until-now-qt-under-windows-is.html#!/2012/12/since-until-now-qt-under-windows-is.html)
On linux/MacOSX you must make sure you have all the necessary prerequisites installed or the compile will fail.
gem install qtbindings
This should always work flawlessly on Windows because everything is nicely packaged into a binary gem. However, the gem is very large ~90MB, so please be patient while gem downloads the file.
To get help: You can file tickets here at github for issues specific to the qtbindings gem.
License: This library is released under the LGPL Version 2.1. See COPYING.LIB.txt
Contributing: Fork the project and submit pull requests.
Disclaimer: Almost all of this code was written by the guys who worked on the KDE bindings project, particurly Arno Rehn and Richard Dale. I hope to increase the adoption and use of the code that they have written.