Monday, March 30, 2009

rbuic4

Command rbuic4 is a generator from Qt Designer's XML file that defines user interface to ruby script. Qt 4.5 SDK contains some UI demos and UI examples. Let's try to generate ruby scripts from these UI files with below ruby codes:
qt_dir = '/opt/qtsdk-2009.01/qt'
target_dir = '/path/to/target_dir'
`find #{qt_dir}/demos #{qt_dir}/examples -name '*.ui'`.split.each do |ui_file|
  basename = File.basename ui_file, '.ui'
  `/opt/ruby-1.9.1/bin/rbuic4 #{ui_file} -x -o #{target_dir}/#{basename}.rb`
end

Ruby script files are generated, but these files are written in non-rubyish style (in addition, less object-oriented style).

For example, launch one of generated script, default.rb.
>/opt/ruby-1.9.1/bin/ruby default.rb

Saturday, March 28, 2009

IDE for Ruby 1.9.1

For Qt 4.5, there is a IDE named "Qt Creator". For Ruby 1.8.x, there are many IDEs. But for Ruby 1.9.1, IDEs that support 1.8.x don't support yet. Please see InfoQ's article for more information.

But, except syntax of Ruby 1.9.1, IDEs work almost fine. So I planned to use one of ruby IDE, NetBeans. I choose ruby download bundle, neither all-in-one bundle and JavaSE bundle and so on. I download, install, and launch this IDE.

If LD_LIBRARY_PATH must be edited, see also #3, and launch from command line with edited LD_LIBRARY_PATH.

After adding Ruby 1.9.1 platform in menu Tools -> Ruby Platforms, I write one sample program from Rapid GUI Development with QtRuby, and run on the IDE. This result is below:

Thursday, March 26, 2009

Introductory textbook

Some tutorials are helpful for studying QtRuby. I found 2 introductory textbooks on the web.

First, Rapid GUI Development with QtRuby from The Pragmatic Bookshelf. This book(PDF; $8.50) is written in Qt version 3.x and with less rubyish way, but contains all basis of QtRuby. Of course, It can use for Qt version 4.x in intact, except one method.
app.setMainWidget(...)

Because, QApplication::setMainWidget() is non-existent from Qt version 4.x, until 3.x. So appropriate line of sample codes should be commented.

Second, QtRuby examples of KDE TechBase. This page introduces above book and some sample codes in Qt version 4.x and with rubyish way. And this page also introduces to mailing-list and to RubyForge of KDE-bindings.

Wednesday, March 25, 2009

qt4-qtruby 2.0.3 is released

A few hours ago, qt4-qtruby 2.0.3 is released. This release is built from svn trunk that I have tried to build(#1, #2, #3). So building instructions are mostly same. See below, full instructions.
>tar -zxf qt4-qtruby-2.0.3.tgz
>cd qt4-qtruby-2.0.3
>cmake \
> -DCMAKE_INSTALL_PREFIX=/opt/ruby-1.9.1 \
> -DRUBY_EXECUTABLE=/opt/ruby-1.9.1/bin/ruby \
> -DRUBY_LIBRARY=/opt/ruby-1.9.1/lib/libruby.so.1.9.1 \
> -DRUBY_INCLUDE_PATH=/opt/ruby-1.9.1/include/ruby-1.9.1 \
> -DQT_QMAKE_EXECUTABLE=/opt/qtsdk-2009.01/qt/bin/qmake \
> -Wno-dev \
> -DENABLE_SMOKE=on \
> -DENABLE_QTRUBY=on \
> -DENABLE_QTWEBKIT_SMOKE=off \
> -DENABLE_QTSCRIPT_SMOKE=off \
> -DENABLE_QTUITOOLS_SMOKE=off \
> -DENABLE_QTTEST_SMOKE=off \
> -DENABLE_PHONON_SMOKE=off \
> -DENABLE_QSCI_SMOKE=off \
> -DENABLE_QWT_SMOKE=off \
> -DENABLE_KDE_SMOKE=off \
> -DENABLE_KDEVPLATFORM_SMOKE=off \
> -DENABLE_KHTML_SMOKE=off \
> -DENABLE_KTEXTEDITOR_SMOKE=off \
> -DENABLE_SOLID_SMOKE=off \
> -DENABLE_PLASMA_SMOKE=off \
> -DENABLE_QTWEBKIT_RUBY=off \
> -DENABLE_QTUITOOLS_RUBY=off \
> -DENABLE_QTSCRIPT=off \
> -DENABLE_QTTEST=off \
> -DENABLE_PHONON_RUBY=off \
> -DENABLE_QSCINTILLA_RUBY=off \
> -DENABLE_QWT_RUBY=off \
> -DENABLE_SOPRANO_RUBY=off \
> -DENABLE_KDEVPLATFORM_RUBY=off \
> -DENABLE_KORUNDUM_RUBY=off \
> -DENABLE_KHTML_RUBY=off \
> -DENABLE_KTEXTEDITOR_RUBY=off \
> -DENABLE_SOLID_RUBY=off \
> -DENABLE_KROSSRUBY=off \
> -DENABLE_PLASMA_RUBY=off \
> -DENABLE_QIMAGEBLITZ_SMOKE=off
>make
>sudo make install

If shebang line or LD_LIBRARY_PATH must be edited, see also #3.

Let's check installation.
>/opt/ruby-1.9.1/bin/irb
irb(main):001:0> require 'Qt4'
=> true

And, let's check other commands.
>/opt/ruby-1.9.1/bin/rbrcc -version
Ruby Resource Compiler for Qt version 4.5.0
>/opt/ruby-1.9.1/bin/rbuic4 -v
Qt User Interface Compiler version 4.5.0
>/opt/ruby-1.9.1/bin/rbqtapi -v
QtRuby 2.0.3 using Qt-4.5.0

Monday, March 23, 2009

Build QtRuby with Ruby 1.9.1 and Qt 4.5 #3

(continued from phosphorescence: Build QtRuby with Ruby 1.9.1 and Qt 4.5 #2)

LoadError occurs when required libraries (shared libraries or gems, etc.) are not found. Default libraries are that of ruby 1.8.7 and of Qt 4.4; these are on the load path. But my target libraries are not.

I should set load path, by using $LD_LIBRARY_PATH. Ruby 1.9.1's library path is /opt/ruby-1.9.1/lib and Qt 4.5's library path is /opt/qtsdk-2009.01/qt/lib. Setting in bash is below:
if [ -d '/opt/ruby-1.9.1/lib' ] ; then
  export LD_LIBRARY_PATH='/opt/ruby-1.9.1/lib':$LD_LIBRARY_PATH
fi
if [ -d '/opt/qtsdk-2009.01/qt/lib' ] ; then
  export LD_LIBRARY_PATH='/opt/qtsdk-2009.01/qt/lib':$LD_LIBRARY_PATH
fi

For KDE user, above shell script can't set /etc/bashrc, /etc/profile, .bashrc, .profile, and so on. Because default KDE is built with default Qt, and KDE will be confused if non-default Qt is loaded. So above shell script should be hand-operated.

Then check $LD_LIBRARY_PATH.
>echo $LD_LIBRARY_PATH
/opt/ruby-1.9.1/lib:/opt/qtsdk-2009.01/qt/lib:/usr/lib64/mpi/gcc/openmpi/lib64

Retry irb.
>/opt/ruby-1.9.1/bin/irb
irb(main):001:0> require 'Qt'
=> true

Let's check executable files of QtRuby.
>/opt/ruby-1.9.1/bin/rbrcc -version
Ruby Resource Compiler for Qt version 4.5.0
>/opt/ruby-1.9.1/bin/rbuic4 -v
Qt User Interface Compiler version 4.5.0
>/opt/ruby-1.9.1/bin/rbqtapi -v
/usr/lib64/ruby/site_ruby/1.8/x86_64-linux/qtruby4.so: /usr/lib64/ruby/site_ruby/1.8/x86_64-linux/qtruby4.so: undefined symbol: classname - /usr/lib64/ruby/site_ruby/1.8/x86_64-linux/qtruby4.so (LoadError)
from /usr/lib64/ruby/site_ruby/1.8/Qt4.rb:5
from /opt/ruby-1.9.1/bin/rbqtapi:6:in `require'
from /opt/ruby-1.9.1/bin/rbqtapi:6

What happen in rbqtapi. show this file until line 6.
#!/usr/bin/env ruby

# Note: this program is part of qtruby and makes use of its internal functions.
# You should not rely on those in your own programs.

require 'Qt4'

Line 1, shebang indicates ruby on the $PATH. Normally, ruby 1.9.1 executable should be added to $PATH, but I planned to rewrite shebang locally.
#!/opt/ruby-1.9.1/bin/ruby

Retry rbqtapi.
>/opt/ruby-1.9.1/bin/rbqtapi -v
QtRuby 2.0.2 using Qt-4.5.0

Finally, Build succeeds!

Saturday, March 21, 2009

Build QtRuby with Ruby 1.9.1 and Qt 4.5 #2

(continued from phosphorescence: Build QtRuby with Ruby 1.9.1 and Qt 4.5 #1)

First, cmake finds default Ruby.
-- Ruby found: /usr/lib64/libruby.so

I certainly set -DRUBY_EXECUTABLE=/opt/ruby-1.9.1/bin/ruby and -DRUBY_INCLUDE_PATH=/opt/ruby-1.9.1/include/ruby-1.9.1. What do I lack? I seek the file related to cmake's ruby options, then it's found: cmake/modules/FindRUBY.cmake. At line 80~82 in this file, notable block is found.
IF(NOT RUBY_FIND_QUIETLY)
  MESSAGE(STATUS "Ruby found: ${RUBY_LIBRARY}")
ENDIF(NOT RUBY_FIND_QUIETLY)

I guess cmake requires -DRUBY_LIBRARY, so I should set path to ruby 1.9.1's shared library.

I mentioned in phosphorescence: Install Ruby 1.9.1, I forgot --enable-shared option. So I again build ruby 1.9.1 with --enable-shared option, then shared library was created.

Second, cmake finds default Qt.
-- Found Qt-Version 4.4.3 (using /usr/bin/qmake)

I remember not to set cmake's Qt options, so I seek related file, then it's found: cmake/modules/FindQt4.cmake. At line 1423~1425 in this file, notable block is found.
IF( NOT Qt4_FIND_QUIETLY)
  MESSAGE(STATUS "Found Qt-Version ${QTVERSION} (using ${QT_QMAKE_EXECUTABLE})")
ENDIF( NOT Qt4_FIND_QUIETLY)

I guess cmake requires -DQT_QMAKE_EXECUTABLE, so I should set Qt 4.5's qmake path.

Clean and retry building QtRuby.
test -r Makefile && make clean
rm CMakeCache.txt CMakeFiles/*log

>cmake \
>-DCMAKE_INSTALL_PREFIX=/opt/ruby-1.9.1 \
>-DRUBY_EXECUTABLE=/opt/ruby-1.9.1/bin/ruby \
>-DRUBY_INCLUDE_PATH=/opt/ruby-1.9.1/include/ruby-1.9.1 \
>-DRUBY_LIBRARY=/opt/ruby-1.9.1/lib/libruby.so.1.9.1 \
>-DQT_QMAKE_EXECUTABLE=/opt/qtsdk-2009.01/qt/bin/qmake \
>...

Check the appropriate output.
-- Found Qt-Version 4.5.0 (using /opt/qtsdk-2009.01/qt/bin/qmake)
-- Ruby found: /opt/ruby-1.9.1/lib/libruby.so.1.9.1

That's OK. Rest instruction goes. It takes a few minutes.
make
sudo make install

CMMI instructions succeed at this time. Result is shown on standard output and install_manifest.txt file in current directory.

So let's begin happy QtRuby computing. Launch irb.
>/opt/ruby-1.9.1/bin/irb
irb(main):001:0> require 'Qt'
LoadError: /opt/ruby-1.9.1/lib/ruby/site_ruby/1.9.1/x86_64-linux/qtruby4.so: undefined symbol: IdToClassNameMap - /opt/ruby-1.9.1/lib/ruby/site_ruby/1.9.1/x86_64-linux/qtruby4.so
from /opt/ruby-1.9.1/lib/ruby/site_ruby/1.9.1/Qt.rb:1:in `require'
from /opt/ruby-1.9.1/lib/ruby/site_ruby/1.9.1/Qt.rb:1:in `'
from (irb):1:in `require'
from (irb):1
from /opt/ruby-1.9.1/bin/irb:12:in `
'

Well, It's still unhappy. to be continued...

Friday, March 20, 2009

Build QtRuby with Ruby 1.9.1 and Qt 4.5 #1

openSUSE 11.1 also supports QtRuby. Its packege name is "ruby-kde4" because openSUSE's rpm manages both QtRuby and Korundum(KDE bindings for Ruby) as one.
>rpm -q ruby-kde4
ruby-kde4-4.1.3-1.20

Of course, this one is built with package's ruby(1.8.7) and Qt(4.4.3). I should build with ruby(1.9.1) and Qt(4.5). How? I sought that in rubyforge, then found in forum. Thanks, Davor. I follow instructions written in this link. Davor's patch has been merged to svn trunk currently.
>svn co svn://anonsvn.kde.org/home/kde/trunk/KDE/kdebindings
>svn co svn://anonsvn.kde.org/home/kde/trunk/KDE/kdelibs
>cd kdebindings
>cp CMakeLists.txt.qtruby CMakeLists.txt
>cp ../kdelibs/cmake/modules/FindQt4.cmake ./cmake/modules/
>cp ../kdelibs/cmake/modules/FindRUBY.cmake ./cmake/modules/
>cp ../kdelibs/cmake/modules/MacroOptionalFindPackage.cmake ./cmake/modules/
>cp ../kdelibs/cmake/modules/MacroPushRequiredVars.cmake ./cmake/modules/

And create symlink from config.h to include path.
>sudo ln -s /opt/ruby-1.9.1/include/ruby-1.9.1/x86_64-linux/ruby/config.h /opt/ruby-1.9.1/include/ruby-1.9.1/ruby/config.h

Then I make cmake with build options. For my ruby 1.9.1 environment(phosphorescence: Install Ruby 1.9.1), I planned to took these values:
>cmake \
>-DCMAKE_INSTALL_PREFIX=/opt/ruby-1.9.1 \
>-DRUBY_EXECUTABLE=/opt/ruby-1.9.1/bin/ruby \
>-DRUBY_INCLUDE_PATH=/opt/ruby-1.9.1/include/ruby-1.9.1 \
>...

But I found notable 2 messages in output of cmake.
-- Found Qt-Version 4.4.3 (using /usr/bin/qmake)
-- Ruby found: /usr/lib64/libruby.so

Ouch! they are default Qt and Ruby. Unfortunately, defaults are not my build targets. to be continued...

Wednesday, March 18, 2009

Install Qt 4.5 SDK

openSUSE 11.1 supports KDE 3.5 and 4.1. I choose KDE 4.1 as my desktop environment, so Qt 4.4 is already installed.
>rpm -q libqt4
libqt4-4.4.3-4.8.2

I planned to install another Qt - that is Qt 4.5. This version of Qt has dual licenses (commercial/LGPL), and two package types(SDK/libraries only). I download Qt 4.5 SDK (LGPL) from here, and launch GUI installer at root-user.
#./qt-sdk-linux-x86_64-opensource-2009.01.bin

I operate installation wizard with default values(installation root; /opt/qtsdk-2009.01). Qt 4.5 SDK contains sources, libraries(on /opt/qtsdk-2009.01/qt), and some GUI tools(on /opt/qtsdk-2009.01/bin).

Tuesday, March 17, 2009

Install Ruby 1.9.1

openSUSE's package system is rpm, and openSUSE 11.1 supports ruby 1.8.7
>rpm -q ruby
ruby-1.8.7.p72-5.3
>which ruby
/usr/bin/ruby
>ruby -e "puts $:"
/usr/lib64/ruby/site_ruby/1.8
/usr/lib64/ruby/site_ruby/1.8/x86_64-linux
/usr/lib64/ruby/site_ruby
/usr/lib64/ruby/vendor_ruby/1.8
/usr/lib64/ruby/vendor_ruby/1.8/x86_64-linux
/usr/lib64/ruby/vendor_ruby
/usr/lib64/ruby/1.8
/usr/lib64/ruby/1.8/x86_64-linux

So I planned to install ruby 1.9.1 not on /usr/, on /opt/. First, get the source code from here, uncompress, and change directory. then CMMI instructions start, with some configure options.
>./configure --prefix=/opt/ruby-1.9.1 --enable-shared
>make
>sudo make install

--prefix option decides installation root(/opt/ruby-1.9.1), --enable-shared option builds ruby and its shared library(ex. libruby.so.1.9.1). Actually, I forgot --enable-shared option, then build of ruby itself succeeds, but in later instruction, I met some failures. I will post about it later.

The First Post

Hi,
I begin blogging to study QtRuby and to write English for my own. I will post technical tips of Qt, Ruby, maybe and more.

My first goal is to run QtRuby built with Ruby 1.9.1 (released at Jan 2009) and Qt 4.5 (released at Mar 2009) on openSUSE 11.1.