Qt and Ruby on Windows and Mac

I use ruby at work (windows) from time to time to fill my lightweight scripting needs (breaking out visual studio 2005/C# to reformat a couple of hundred lines of text is a bit overkill).  If I have any user interaction (which I typically do not) I just prompt for input through the command line, but occasionally I’ve wanted to have an actual GUI.  I did a search and discovered the cross-platform GUI toolkit Qt and a Qt-Ruby binding so that one could call the other.

Qt on Windows

Some more searching revealed a pre-packaged install for windows.  I followed the directions in a handy guide. The install went almost perfectly, except that I already had MinGW installed.  I had the most recent version (I even ran the updater to make sure) but the version of win32api.h I had was lower than that required by the qt installer.  I checked the sourceforge repository and I did have the latest version listed.  I tried to complete the installation anyway, and when qt finished and ran it’s demo app, it was messed up (screen garbled).

During the process of installing Qt, it gives one the option to use the existing MinGW, or install one from the package.  During my second attempt, I opted to have the installer provide MinGW.  It downloaded a copy from trolltech (the  Qt maker) and installed over my existing copy of minGW (I have no clue if this has broken it yet; I haven’t used it since).  The installer completed, and the Qt (technically pronounced “Cute”, but I still say “Queue – Tee”) demo app ran correctly.  A quick test later and I had verified it working in ruby as well,

Qt on Mac

Installing Qt on the Mac is a tad bit different, both harder and easier.  I primarily followed this guide, but I had a few issues which will be documented here.  Note that the guide was made for Os X 10.4 Tiger.  The Ruby included in that version of the OS was broken, so the first step in the guide is installing a later version of Ruby and disabling the one that comes by default on the system.  This is not necessary for 10.5 Leopard.

The first thing one needs to do is download Qt and install it. I downloaded the Qt 4.5, LGPL/Free, Framework Only.  After that you need to download Mac Ports.

If you aren’t aware, OS X is based off of BSD.  Rather than using the Red Hat Linux RPM package managing system that most flavors of linux use, BSD used the ports system.  The ports sytem is basically directory tree off all the applications availible for BSD, organized by category (math, games, etc.).  Each application has its own folder, maintained by some person.  Inside the folder are pointers to all the files needed to install the program.  The person maintaining the folder is responsible for making sure the files are up to date and always compile.  Mac Ports is a Mac specific version of the ports sytem.  All the programs are maintained to compile and run on OS X. (Fink is a similar program that can help you get and install *nix programs).

We will be using Mac Ports to get cmake, a specialized makefile generator that is required to install the qt-ruby bindings (which you also need to download). I downloaded  qt4-qtruby-2.0.3, the latest version at this time.

Now it is time to install.  As per the guide:

Install Qt and Mac Ports.

Install cmake from the terminal:

cd ~/Desktop
sudo port install cmake   ## CMake is a cool build system

This is where I had to deviate from the guide.  When I called :

cmake .
make && sudo make install

cmake completed but building failed:

[ 38%] Building CXX object smoke/qtwebkit/CMakeFiles/smokeqtwebkit.dir/smokedata.o
[ 40%] Building CXX object smoke/qtwebkit/CMakeFiles/smokeqtwebkit.dir/x_1.o
i686-apple-darwin9-g++-4.0.1: /Users/Zack/Desktop/qt4-qtruby-2.0.3/smoke/qtwebkit/x_1.cpp: No such file or directory
i686-apple-darwin9-g++-4.0.1: no input files
make[2]: *** [smoke/qtwebkit/CMakeFiles/smokeqtwebkit.dir/x_1.o] Error 1
make[1]: *** [smoke/qtwebkit/CMakeFiles/smokeqtwebkit.dir/all] Error 2
make: *** [all] Error 2

I break out my Google-Foo(tm) and start searching for answers.  I track down a post on ruby forge giving me the answer:  Qt did not install with webkit support, so cmake could not find the qtwebkit cpp headers.  The easiest thing to do (for me at least) is just to disable qtwebkit support (the other option is to build and reinstall Qt from source).


I run build again and get a new error:

[100%] Building CXX object ruby/qttest/CMakeFiles/qttest.dir/qttesthandlers.o
Linking CXX shared module qttest.so
ld: library not found for -lsmokekde
collect2: ld returned 1 exit status
make[2]: *** [ruby/qttest/qttest.so] Error 1
make[1]: *** [ruby/qttest/CMakeFiles/qttest.dir/all] Error 2
make: *** [all] Error 2

The answer lies further up in the previous post.


Finally, everything builds and installs.

Qt Ruby DemoQt Ruby Demo

You can find a nice little qt-ruby tutorial here: http://www.darshancomputing.com/qt4-qtruby-tutorial/


  1. Katy
    Posted June 23, 2009 at 10:31 pm | Permalink

    Pretty cool post. I just found your blog and wanted to say
    that I have really enjoyed browsing your blog posts. Anyway
    I’ll be subscribing to your feed and I hope you write again soon!

  2. Posted October 6, 2009 at 5:11 pm | Permalink

    Qt on Mac section saved, rather quelled an existing headache.

    Thanks so much.

    I will recommend your google-foo over my own to anyone.

  3. Posted March 20, 2010 at 6:27 am | Permalink

    That was a fun comment. Thanks for reading and for taking the time to leave word that you were here and got something from it.

  4. Posted September 16, 2010 at 8:00 am | Permalink

    I used to work on a weblog just like yours, for some reason I gave up.. Definitely keep up the good work, you’re a great webmaster! 😉