Archive for October, 2006

Howto install QT 4.2 and QtRuby 1.4.6 on Mac OS X Tiger

Monday, October 16th, 2006 at 6:30 pm

I had some (minor?) trouble to get QtRuby 1.4.6 and QT 4.2 running on my Mac (PowerPC, 10.4.8). However, with some help from Richard Dale (thank you!) and the Korundum forum I got it working.

Install QT 4.2

First, download QT 4.2 for your Mac. Unpack it and configure it with at least the “-no-framework” option, the remaining parameters are as far as I know up to you. And DON’T use the -prefix option (some people recommended this to put it in /Developer/qt), otherwise QtRuby 1.4.6 won’t find the QT stuff (Default installation path of QT is currently /usr/local/Trolltech/Qt-4.2.0).

>  ./configure -no-framework -system-zlib -qt-gif -qt-libpng -no-debug \
            -no-stl -no-exceptions -fast
 
>  make
>  sudo make install
>  export QTDIR=/usr/local/Trolltech/Qt-4.2.0
>  export PATH=$QTDIR/bin:$PATH</code>

Install QtRuby

Note: This is only to get version <=1.4.6 to work !!!

  • Fix missing headers – don’t link them, copy them (otherwise the build script will fail!)
    > sudo cp /usr/lib/ruby/1.8/universal-darwin8.0/*.h /usr/lib/ruby/1.8/powerpc-darwin8.0
  • Check out some updates of kalyptus we need to add to QtRuby Release 1.4.6
    svn co -r 588725 svn://anonsvn.kde.org/home/kde/trunk/KDE/kdebindings/kalyptus/
  • Download qt4-qtruby 1.4.6 and unpack
  • Copy from the previous svn checkout the files “kalyptus” and “kalyptusCxxToSmoke.pm” into the kalyptus folder of qtruby
  • According to this article we need to comment out the main() function of qtruby/bin/qtrubyinit.cpp
  • In the root of qt4-qtruby you run:
    > ./configure --with-smoke="qt" --enable-mac --with-qt-dir=/usr/local/Trolltech/Qt-4.2.0 
    > make
    > make install
    > cd /ruby/lib/ruby/site_ruby/1.8/powerpc-darwin8.0 
    > sudo mv qtruby.so qtruby.bundle
  • Test your Qt installation:
    > irb
    irb(main):001:0> 
      require 'Qt'
      a = Qt::Application.new(ARGV)
      hello = Qt::PushButton.new("Hello World!", nil)
      hello.resize(150, 50)
      hello.show()
      a.exec()

Enjoy playing with QtRuby ;)
Thanks to all developers making this possible and thanks for the support!

by markus

R from an OO perspective: modifiers / mutators

Monday, October 2nd, 2006 at 2:36 pm

WARNING: I am completely new to R and I might be wrong here, so please be aware ;)

The reason for this post is, that I haven’t found a throughout short example of a S4 class with methods able to change slots aka. fields (mutator methods).

THE main annoyance with R (IMHO) is that there are no ways to pass values by reference. You need some “tricks” to be able to modify the slots of an object (otherwise you just end up with changing the slots of a copy of the actual object ;).

This short example should give you an idea of how we can modify slots of an object in R which allows mutator methods. Browsing some mailing lists I basically found two ways of doing so: setReplaceMethod which returns the object copy and replaces the original object or the “eval.parent(substitute( … ))” trick. But see yourself:

#define a pythagoras class as an example, holding a, b anc c as numeric values.
setClass("Pythagoras",
   representation = representation(a="numeric", b="numeric", c="numeric"),
   prototype = prototype(a = 1, b = 1, c = sqrt(2))
)
 
 
#define a method to calculate the hypotenuse given a and b 
setGeneric("Pythagoras.hyp", 
function(x) standardGeneric("Pythagoras.hyp"))
 
#implement this method
setMethod("Pythagoras.hyp", signature(x="Pythagoras"), function(x) {
	eval.parent(substitute(
		x@c <- sqrt(x@a^2 + x@b^2)
	))
})
 
 
#define a method to set value a and also update the hypotenuse accordingly
setGeneric("Pythagoras.setA<-", 
function(x, value) standardGeneric("Pythagoras.setA<-"))
 
#implement this method
setReplaceMethod("Pythagoras.setA", "Pythagoras", function(x, value) { 
	x@a <- value
        Pythagoras.hyp(x)
	x
})
 
 
#define a method to set value b and also update the hypotenuse accordingly
setGeneric("Pythagoras.setB<-", 
function(x, value) standardGeneric("Pythagoras.setB<-")) 
 
#implement this method
setReplaceMethod("Pythagoras.setB", "Pythagoras", function(x, value) { 
	x@b <- value
        Pythagoras.hyp(x)
	x
})
 
 
#tests
p = new("Pythagoras")
 
p
 
Pythagoras.setA(p) = 5
 
p
 
Pythagoras.setB(p) = 5
 
p

Beaware: Copy and paste sometimes doesn’t work as the double quotes are no real double quotes!

Give it a try. It will be self explaining by then …
If you have any comments, please let me know!

by markus