{"id":12,"date":"2009-06-20T08:56:57","date_gmt":"2009-06-20T14:56:57","guid":{"rendered":"http:\/\/curiosity.roguepenguin.net\/?p=12"},"modified":"2019-05-13T06:53:30","modified_gmt":"2019-05-13T12:53:30","slug":"qt-and-ruby-on-windows-and-mac","status":"publish","type":"post","link":"http:\/\/curiosity.roguepenguin.net\/?p=12","title":{"rendered":"Qt and Ruby on Windows and Mac"},"content":{"rendered":"<p>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). &nbsp;If I have any user interaction (which I typically do not) I just prompt for input through the command line, but occasionally I&#8217;ve wanted to have an actual GUI. &nbsp;I did a search and discovered the cross-platform GUI toolkit Qt and a Qt-Ruby binding so that one could call the other.<\/p>\n<h2>Qt on Windows<\/h2>\n<p>Some more searching revealed a pre-packaged install for windows. &nbsp;I followed the directions in a <a href=\"http:\/\/tom.paschenda.org\/blog\/?p=38\">handy guide<\/a>. The install went almost perfectly, except that I already had MinGW installed. &nbsp;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. &nbsp;I checked the sourceforge repository and I did have the latest version listed. &nbsp;I tried to complete the installation anyway, and when qt finished and ran it&#8217;s demo app, it was messed up (screen garbled).<\/p>\n<p>During the process of installing Qt, it gives one the option to use the existing MinGW, or install one from the package. &nbsp;During my second attempt, I opted to have the installer provide MinGW. &nbsp;It downloaded a copy from trolltech (the &nbsp;Qt maker) and installed over my existing copy of minGW (I have no clue if this has broken it yet; I haven&#8217;t used it since). &nbsp;The installer completed, and the Qt (technically pronounced &#8220;Cute&#8221;, but I still say &#8220;Queue &#8211; Tee&#8221;) demo app ran correctly. &nbsp;A quick test later and I had verified it working in ruby as well,<\/p>\n<h2>Qt on Mac<\/h2>\n<p>Installing Qt on the Mac is a tad bit different, both harder and easier. &nbsp;I primarily followed <a href=\"http:\/\/blog.paulbetts.org\/index.php\/2007\/07\/22\/cross-platform-ui-with-qt4-and-ruby-maclinux-howto\/\">this guide<\/a>, but I had a few issues which will be documented here. &nbsp;Note that the guide was made for Os X 10.4 Tiger. &nbsp;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. &nbsp;This is <strong>not<\/strong> necessary for 10.5 Leopard.<\/p>\n<p>The first thing one needs to do is <a href=\"http:\/\/www.qtsoftware.com\/\">download Qt<\/a> and install it. I downloaded the Qt 4.5, LGPL\/Free, Framework Only. &nbsp;After that you need to download <a href=\"http:\/\/www.macports.org\/index.php\">Mac Ports<\/a>.<\/p>\n<p>If you aren&#8217;t aware, OS X is based off of BSD. &nbsp;Rather than using the Red Hat Linux RPM package managing system that most flavors of linux use, BSD used the <a href=\"http:\/\/en.wikipedia.org\/wiki\/FreeBSD_Ports\">ports system<\/a>. &nbsp;The ports sytem is basically directory tree off all the applications availible for BSD, organized by category (math, games, etc.). &nbsp;Each application has its own folder, maintained by some person. &nbsp;Inside the folder are pointers to all the files needed to install the program. &nbsp;The person maintaining the folder is responsible for making sure the files are up to date and always compile. &nbsp;Mac Ports is a Mac specific version of the ports sytem. &nbsp;All the programs are maintained to compile and run on OS X. (<a href=\"http:\/\/www.finkproject.org\/\">Fink<\/a> is a similar program that can help you get and install *nix programs).<\/p>\n<p>We will be using Mac Ports to get cmake, a specialized makefile generator that is required to install the <a href=\"http:\/\/rubyforge.org\/frs\/?group_id=181\">qt-ruby bindings<\/a> (which you also need to download). I downloaded &nbsp;qt4-qtruby-2.0.3, the latest version at this time.<\/p>\n<p>Now it is time to install. &nbsp;As per <a href=\"http:\/\/blog.paulbetts.org\/index.php\/2007\/07\/22\/cross-platform-ui-with-qt4-and-ruby-maclinux-howto\/\">the guide<\/a>:<\/p>\n<p>Install Qt and Mac Ports.<\/p>\n<p>Install cmake from the terminal:<\/p>\n<pre><strong><span style=\"color: #ff0000;\">cd<\/span> ~\/Desktop\n<\/strong><strong>sudo port install cmake   <\/strong>## CMake is a cool build system<\/pre>\n<p>This is where I had to deviate from the guide. &nbsp;When I called :<\/p>\n<pre><strong>cmake .\nmake &amp;&amp; sudo make install<\/strong><\/pre>\n<p>cmake completed but building failed:<\/p>\n<pre><strong>[ 38%] <span style=\"color: #008000;\">Building CXX object smoke\/qtwebkit\/CMakeFiles\/smokeqtwebkit.dir\/smokedata.o<\/span>\n[ 40%] <span style=\"color: #008000;\">Building CXX object smoke\/qtwebkit\/CMakeFiles\/smokeqtwebkit.dir\/x_1.o<\/span>\ni686-apple-darwin9-g++-4.0.1: \/Users\/Zack\/Desktop\/qt4-qtruby-2.0.3\/smoke\/qtwebkit\/x_1.cpp: No such file or directory\ni686-apple-darwin9-g++-4.0.1: no input files\nmake[2]: *** [smoke\/qtwebkit\/CMakeFiles\/smokeqtwebkit.dir\/x_1.o] Error 1\nmake[1]: *** [smoke\/qtwebkit\/CMakeFiles\/smokeqtwebkit.dir\/all] Error 2\nmake: *** [all] Error 2<\/strong><\/pre>\n<p>I break out my Google-Foo(tm) and start searching for answers. &nbsp;I track down a post on ruby forge giving me <a href=\"http:\/\/rubyforge.org\/forum\/forum.php?thread_id=32859&amp;forum_id=723\">the answer<\/a>: &nbsp;Qt did not install with webkit support, so cmake could not find the qtwebkit cpp headers. &nbsp;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).<\/p>\n<pre><strong>cmake -DENABLE_QTWEBKIT_SMOKE=off -DENABLE_QTWEBKIT_RUBY=off .<\/strong><\/pre>\n<p>I run build again and get a new error:<\/p>\n<pre><strong>[100%] <span style=\"color: #008000;\">Building CXX object ruby\/qttest\/CMakeFiles\/qttest.dir\/qttesthandlers.o<\/span>\n<span style=\"color: #ff0000;\">Linking CXX shared module qttest.so<\/span>\nld: library not found for -lsmokekde\ncollect2: ld returned 1 exit status\nmake[2]: *** [ruby\/qttest\/qttest.so] Error 1\nmake[1]: *** [ruby\/qttest\/CMakeFiles\/qttest.dir\/all] Error 2\nmake: *** [all] Error 2\n<\/strong><\/pre>\n<p>The answer lies further up in the previous post.<\/p>\n<pre><strong>cmake -DENABLE_QTWEBKIT_SMOKE=off -DENABLE_QTWEBKIT_RUBY=off -DENABLE_QTTEST=off -DENABLE_QTTEST_SMOKE=off .&nbsp;\n<\/strong><\/pre>\n<p>Finally, everything builds and installs.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-13\" title=\"RubyQt-test\" src=\"http:\/\/curiosity.roguepenguin.net\/wp-content\/uploads\/2009\/06\/rubyscreensnapz001.png\" alt=\"Qt Ruby Demo\" width=\"400\" height=\"456\" srcset=\"http:\/\/curiosity.roguepenguin.net\/wp-content\/uploads\/2009\/06\/rubyscreensnapz001.png 400w, http:\/\/curiosity.roguepenguin.net\/wp-content\/uploads\/2009\/06\/rubyscreensnapz001-263x300.png 263w\" sizes=\"auto, (max-width: 400px) 100vw, 400px\" \/>Qt Ruby Demo<\/p>\n<p>You can find a nice little qt-ruby tutorial here: <a href=\"http:\/\/www.darshancomputing.com\/qt4-qtruby-tutorial\/\">http:\/\/www.darshancomputing.com\/qt4-qtruby-tutorial\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Setting up Qt and Ruby<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6,7],"tags":[8,15],"class_list":["post-12","post","type-post","status-publish","format-standard","hentry","category-programming","category-ruby","tag-qt","tag-ruby"],"_links":{"self":[{"href":"http:\/\/curiosity.roguepenguin.net\/index.php?rest_route=\/wp\/v2\/posts\/12","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/curiosity.roguepenguin.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/curiosity.roguepenguin.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/curiosity.roguepenguin.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/curiosity.roguepenguin.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=12"}],"version-history":[{"count":6,"href":"http:\/\/curiosity.roguepenguin.net\/index.php?rest_route=\/wp\/v2\/posts\/12\/revisions"}],"predecessor-version":[{"id":63,"href":"http:\/\/curiosity.roguepenguin.net\/index.php?rest_route=\/wp\/v2\/posts\/12\/revisions\/63"}],"wp:attachment":[{"href":"http:\/\/curiosity.roguepenguin.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=12"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/curiosity.roguepenguin.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=12"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/curiosity.roguepenguin.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=12"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}