{"id":38,"date":"2008-10-15T08:11:08","date_gmt":"2008-10-15T06:11:08","guid":{"rendered":"http:\/\/tom.paschenda.org\/blog\/?p=38"},"modified":"2011-06-20T23:01:37","modified_gmt":"2011-06-20T21:01:37","slug":"getting-qt-and-ruby-qtruby-running-on-windows-xp","status":"publish","type":"post","link":"https:\/\/tom.paschenda.org\/blog\/?p=38","title":{"rendered":"Getting Qt and Ruby (=QtRuby) running on Windows XP"},"content":{"rendered":"<p><strong>Important note<\/strong><\/p>\n<p>An update on this post is <a href=\"http:\/\/tom.paschenda.org\/blog\/?p=43\">available here<\/a>. The improvements are<\/p>\n<ul>\n<li>only 6 steps instead of 10<\/li>\n<li>QtRuby 2.1.0 instead of whatever old version is installed by the guide below<\/li>\n<li>Qt 4.6.1 instead of Qt 4.3.4<\/li>\n<li>Ruby 1.8.7 instead of Ruby 1.8.6<\/li>\n<\/ul>\n<p><strong>This is a tutorial about writing Ruby applications that use the Qt framework on Windows XP. For doing so, the Qt-Ruby bindings named QtRuby are used. <\/strong><\/p>\n<p>\u2014\u2014RANT MODE: ON\u2014\u2013<\/p>\n<p>Ruby programs that have a nice GUI? Is that possible? With all that Ruby On Rails stuff going on, good old desktop applications have been left behind. And so has the topic of creating a desktop application that is pleasant to use and to code.<\/p>\n<p>When combining Ruby and Qt, developers finally have a chance to create Ruby GUI applications that are neither pain in the ass for developers nor pain in the eye for the user.<\/p>\n<p>\u2014\u2014RANT MODE: OFF\u2014\u2013<\/p>\n<p><strong>Disclaimer<\/strong><br \/>\nAt the time of writing this I have very little experience with QtRuby. However I just wanted to get started with it and did not find a decent guide for doing so on windows, so I just put together what I learned in the first few days.<br \/>\nFor the sake of simplicity and brevity, this guide does not use the latest versions of Ruby, Qt and QtRuby. Instead, it is using prebuilt binaries and installers, that have been created by some nice guys (for getting the latest version running, see comments).<br \/>\nYou have been warned. Comments are welcome.<\/p>\n<p><strong>Setting everything up<\/strong><\/p>\n<p>Getting your first QtRuby program to run under windows is surprisingly simple.<\/p>\n<p><strong>Installing Ruby<\/strong><\/p>\n<ol>\n<li>Download the Ruby 1.8.6.25 One-Click Installer from the official Ruby site: <a href=\"http:\/\/rubyforge.org\/frs\/download.php\/18566\/ruby186-25.exe\" rel=\"nofollow\">http:\/\/rubyforge.org\/frs\/download.php\/18566\/ruby186-25.exe<\/a>. Make sure to use that exact version. Otherwise you might run into dll-version problems (see Yann&#8217;s comment for details).<\/li>\n<li>During installation, check the <em>SciTE<\/em> and <em>Enable RubyGems<\/em> options. SciTE is an editor and Gems is the Ruby package manager (we won&#8217;t need those here, but they are both very handy tools).<\/li>\n<li>Install to <code>c:\\ruby<\/code>. You may of course choose a different path, but for the rest of this guide I will assume this location.<\/li>\n<li>When installation is finished, open a shell and type <code>ruby --version<\/code>. It should say <code>ruby 1.8.6.<\/code><\/li>\n<\/ol>\n<p><strong>Installing Qt<\/strong><\/p>\n<ol>\n<li> Download\u00a0 Qt 4.3.4 Open Source Edition from <a href=\"http:\/\/ftp.ntua.gr\/pub\/X11\/Qt\/qt\/source\/qt-win-opensource-4.3.4-mingw.exe\">ftp.ntua.gr\/pub\/X11\/Qt\/qt\/source\/qt-win-opensource-4.3.4-mingw.exe<\/a> and install it.<\/li>\n<li> During installation,\u00a0 check the <em>Install mingw option <\/em>(if you do not yet have mingw installed). mingw is a gcc (C++ compiler) for Windows. Qt 4.3.4 Open Source comes with precompiled binaries that need the runtime dll (mingwm10.dll) of mingw.<\/li>\n<li> To check, whether the installation worked, go to <em>Start-&gt;Programs-&gt;Qt-&gt;Examples and Demos<\/em>. You should see a window with fancy animation that offers various examples of Qt in action.<\/li>\n<\/ol>\n<p><strong>Installing QtRuby<\/strong><\/p>\n<ol>\n<li>Get the installer from <a href=\"http:\/\/vision.eng.shu.ac.uk\/mmvlwiki\/index.php\/Qt4-QtRuby_installer_for_Microsoft_Windows\">vision.eng.shu.ac.uk\/mmvlwiki\/index.php\/Qt4-QtRuby_installer_for_Microsoft_Windows<\/a> and install it.<\/li>\n<li>Open irb (that&#8217;s a Ruby shell) by typing <code>irb<\/code> at your Windows shell.<\/li>\n<li>Type <code>require 'Qt4'<\/code> and execute it by pressing Enter. It should yield true<\/li>\n<\/ol>\n<p><strong>That&#8217;s it!<\/strong> Now you are ready to begin development of QtRuby programs.<br \/>\nYou may leave now if you want and hack away on your own. However, if you want some advice on how to start and where to get information, I kindly invite you to stay a bit longer.<\/p>\n<p><strong>Hello Qt, Hello Ruby!<\/strong><\/p>\n<p>Let&#8217;s see if we can greet our new friends. Type the following program into the irb. Alternatively you may copy-paste the code into a fresh file. Name it main.rb and run it with <code>ruby main.rb<\/code>.<\/p>\n<p><code>require 'Qt'<br \/>\napp = Qt::Application.new(ARGV)<br \/>\nbutton=Qt::PushButton.new(\"Hello Ruby, hello Qt!\")<br \/>\nbutton.resize(100,30)<br \/>\nbutton.show<br \/>\napp.exec<\/code><\/p>\n<p><a href=\"http:\/\/tom.paschenda.org\/blog\/wp-content\/uploads\/2008\/10\/helloruby.png\" title=\"Hello Ruby, hello Qt\"><img decoding=\"async\" src=\"http:\/\/tom.paschenda.org\/blog\/wp-content\/uploads\/2008\/10\/helloruby.png\" alt=\"Hello Ruby, hello Qt\" \/><\/a><\/p>\n<p>You should see something that looks strikingly similar to the screenshot.<\/p>\n<p><strong>Getting Help on Qt<\/strong><br \/>\nQt is the best-documented library I have ever seen. You can find everything at<br \/>\n<a href=\"http:\/\/doc.trolltech.com\/4.3\/index.html\">doc.trolltech.com\/4.3<\/a><br \/>\n(The QtRuby version you downloaded has been built against Qt 4.3.1)<\/p>\n<p>The docs are available as an offline version: If you install and compile an open source version of Qt (see this <a href=\"http:\/\/tom.paschenda.org\/blog\/?p=28\">post<\/a> ), you will get a program called Qt Assistant (assisstant.exe) that offers the full documentation and some neat searching features.<br \/>\nWhen installing Qt, you will also get a nice program called qtdemo.exe. It contains lots of example programs (in fact the Regular Expressions &#8216;example&#8217; is one of my favorite tools at work).<\/p>\n<p>However, there is one drawback on both, the documentation and the example programs. It is all written for C++ coders. Damn!<br \/>\nFortunately the difference between C++-Qt and Ruby-Qt is not that big. But it gets even better&#8230;<\/p>\n<p><strong>Tons of Examples (in Ruby!)<\/strong><br \/>\n&#8230;because a very kind guy named Richard Dale converted the Qt examples from C++ to Ruby. They come with the QtRuby source package, that can be found on the Rubyforge homepage of Korundum\/QtRuby (<a href=\"http:\/\/rubyforge.org\/frs\/?group_id=181\">rubyforge.org\/frs\/?group_id=181<\/a>). Let me show you how to get them running (and introduce you to the resource compiler on the way).<\/p>\n<ol>\n<li>Download e.g. <code>qt4-qtruby-1.4.9.tgz<\/code> and unpack it<\/li>\n<li>Browse to the directory <code>qt4-qtruby-1.4.9\\ruby\\qtruby\\examples\\graphicsview\\collidingmice<\/code> and open a shell<\/li>\n<li>Type <code>ruby main.rb<\/code><\/li>\n<li>And tadaah &#8211; you will get an error message saying <code>no such file to load -- qrc_mice.rb (LoadError)<\/code><\/li>\n<\/ol>\n<p>The reason for this error is that the resources (images in this case) have to be available for the program to work. To create the required resource file, we have to execute the Ruby-pendant of the Qt resource compiler (rbrcc, probably located in c:\\ruby\\bin)<br \/>\nType<br \/>\n<code>rbrcc mice.qrc -o qrc_mice.rb<\/code><br \/>\nTry <code>ruby main.rb<\/code> again. This time you should see a window with some mice running around in it.<\/p>\n<p><a href=\"http:\/\/tom.paschenda.org\/blog\/wp-content\/uploads\/2008\/10\/collidingmice.png\" title=\"Colliding Mice Example in Ruby\"><img decoding=\"async\" src=\"http:\/\/tom.paschenda.org\/blog\/wp-content\/uploads\/2008\/10\/collidingmice.png\" alt=\"Colliding Mice Example in Ruby\" \/><\/a><\/p>\n<p><strong>More, More, More<\/strong><br \/>\nWhen finished with this short introduction, I strongly recommend to check out<br \/>\n<a href=\"http:\/\/techbase.kde.org\/Development\/Languages\/Ruby\">techbase.kde.org\/Development\/Languages\/Ruby<\/a><br \/>\nimmediately. It explains how the concepts of Qt\/C++ translate to QtRuby, gives a few nice tricks, that are not possible in C++ and demonstrates some convenient features of QtRuby. There&#8217;s also a bunch of links at the bottom of that page, that points out more resources to learn about QtRuby.<br \/>\nGreat stuff, one small warning: It appears that the example code is written for Qt 3.x. So keep that in mind when copy-pasting it.<\/p>\n<p>Well, that&#8217;s it for now. Happy coding!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Important note An update on this post is available here. The improvements are only 6 steps instead of 10 QtRuby 2.1.0 instead of whatever old version is installed by the guide below Qt 4.6.1 instead of Qt 4.3.4 Ruby 1.8.7 instead of Ruby 1.8.6 This is a tutorial about writing Ruby applications that use the [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11,3],"tags":[],"class_list":["post-38","post","type-post","status-publish","format-standard","hentry","category-ruby","category-software-development"],"_links":{"self":[{"href":"https:\/\/tom.paschenda.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/38","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/tom.paschenda.org\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tom.paschenda.org\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tom.paschenda.org\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/tom.paschenda.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=38"}],"version-history":[{"count":0,"href":"https:\/\/tom.paschenda.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/38\/revisions"}],"wp:attachment":[{"href":"https:\/\/tom.paschenda.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=38"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tom.paschenda.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=38"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tom.paschenda.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=38"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}