Developing Qt4 applications with Ruby 1.9.x

I am running KDE on 32-bit Linux Mint Debian Edition. For several years now I
have been developing Qt-based applications with Ruby 1.8.

Now I'm anxious to move forward and adopt Ruby 1.9 as urged. I can install
1.9.2 from the LMDE repositories, but there doesn't appear to be any Qt4
libraries available. So I thought I'd go right up to date, downloading and
compiling Ruby 1.9.3p0 from scratch, installing it in the /usr/local
hierarchy.

I found, downloaded and extracted the latest Qt4-QtRuby build files. This is
where the headaches began. Running cmake . failed immediately as cmake could
not find Ruby. After scratching my head and searching Google I established
that the CMakeCache.txt file needed some tweaking. To be precise, these lines
needed to be filled out to allow cmake to find the ruby.h file and ruby
executable:

//Path to a file.
RUBY_CONFIG_INCLUDE_DIR:PATH=/usr/local/include/ruby-1.9.1/i686-linux

//Path to a program.
RUBY_EXECUTABLE:FILEPATH=/usr/local/bin/ruby

This, then, allowed me to build and install the Qt4-QtRuby library. But then,
when I went to test it with a very minimal script:

#!/usr/local/bin/ruby -w

require 'Qt4'

app = Qt::Application.new(ARGV)

app.exec()

I get the response:

/usr/local/lib/ruby/site_ruby/1.9.1/Qt/qtruby4.rb:1415: warning: mismatched
indentations at 'end' with 'if' at 1411
/usr/local/lib/ruby/site_ruby/1.9.1/Qt/qtruby4.rb:2527: warning: method
redefined; discarding old method_missing

[...]

/usr/local/lib/ruby/site_ruby/1.9.1/Qt/qtruby4.rb:2527: warning: method
redefined; discarding old const_missing
/usr/local/lib/ruby/site_ruby/1.9.1/Qt/qtruby4.rb:459:in `initialize':
unresolved constructor call Qt::Application (ArgumentError)
        from /usr/local/lib/ruby/site_ruby/1.9.1/Qt/qtruby4.rb:459:in
`initialize'
        from /usr/local/lib/ruby/site_ruby/1.9.1/Qt/qtruby4.rb:2640:in `call'
        from /usr/local/lib/ruby/site_ruby/1.9.1/Qt/qtruby4.rb:2640:in `block
in try_initialize'
        from /usr/local/lib/ruby/site_ruby/1.9.1/Qt/qtruby4.rb:2639:in `catch'
        from /usr/local/lib/ruby/site_ruby/1.9.1/Qt/qtruby4.rb:2639:in
`try_initialize'
        from ./qt.rb:16:in `new'
        from ./qt.rb:16:in `<main>'

(that second warning repeated several hundred times, though I'm not all that
concerned about that.)

The test script works fine under 1.8.7, obviously it doesn't do anything but it
doesn't throw any warnings or errors either.

Doing the same in irb yields

irb(main):001:0> require 'Qt4'
=> true
irb(main):002:0> app = Qt::Application.new(ARGV)
ArgumentError: unresolved constructor call Qt::Application

        from /usr/local/lib/ruby/site_ruby/1.9.1/Qt/qtruby4.rb:459:in
`initialize'
        from /usr/local/lib/ruby/site_ruby/1.9.1/Qt/qtruby4.rb:459:in
`initialize'
        from /usr/local/lib/ruby/site_ruby/1.9.1/Qt/qtruby4.rb:2640:in `call'
        from /usr/local/lib/ruby/site_ruby/1.9.1/Qt/qtruby4.rb:2640:in `block
in try_initialize'
        from /usr/local/lib/ruby/site_ruby/1.9.1/Qt/qtruby4.rb:2639:in `catch'
        from /usr/local/lib/ruby/site_ruby/1.9.1/Qt/qtruby4.rb:2639:in
`try_initialize'
        from (irb):2:in `new'
        from (irb):2
        from /usr/local/bin/irb:12:in `<main>'
irb(main):003:0>

Enquiries on Google haven't been very fruitful, with just a suggestion that
the fault lies in the Qt.cpp file but not much help that I could see on exactly
what the problem is or how to fix it (my knowledge of C++ is sketchy at best).

I have the feeling either that I've missed something very simple, or that Ruby
1.9.x is not yet able to work effectively with Qt4. Is there anybody here who
has encountered this problem? Should I carry on regardless with 1.9.3 and find
another GUI interface to work with, or should I reluctantly revert to 1.8.7?

Rosie

···

--
Mój poduszkowiec jest pełen węgorzy
Currently reading Headlong by Michael Frayn

qtruby works perfectly for me with ruby 1.9.3, so the answer to your last
question is: neither. You just need to find out why qtruby isn't working for
you. Unfortunately, I can't say what's wrong with your installation, but here
are some possibilities which come to my mind:
* have you perhaps the version of qtruby you used with ruby 1.8.7? If so,
maybe that's loaded instead of the new version. Try uninstalling them and see
if anything changes
* at least with older versions of qtruby, it wasn't enough to change the two
parameters you mention in the CMakeCache.txt file to have cmake pick up the
correct ruby version (I don't know whether that's changed recently). To be on
the safe side, you can do the following:
- from the build directory (where you run cmake from) issue the command
   ccmake .
This will give you a very simple GUI where to change the parameters (rather
than doing so by hand as it seems you've done). Press the t key to display
advanced settings, then change the following variables (as an example, I'll
add the values which I use on my system: they'll be different on yours, if
only because you installed ruby 1.9 in /usr/local while I installed it in
/usr):
- CUSTOM_RUBY_SITE_ARCH_DIR: /usr/lib/ruby/site_ruby/1.9.1/x86_64-linux
- CUSTOM_RUBY_SITE_LIB_DIR: /usr/lib/ruby/site_ruby/1.9.1
- RUBY_ARCH_DIR: /usr/lib/ruby/1.9.1/x86_64-linux
- RUBY_CONFIG_INCLUDE_DIR: /usr/include/ruby-1.9.1/x86_64-linux
- RUBY_EXECUTABLE: /usr/bin/ruby
- RUBY_INCLUDE_DIR: /usr/include/ruby-1.9.1
- RUBY_LIBRARY: /usr/lib/libruby19.so
- RUBY_RUBY_LIB_DIR: /usr/lib/ruby/1.9.1
- RUBY_SITEARCH_DIR: /usr/lib/ruby/site_ruby/1.9.1/x86_64-linux
- RUBY_SITELIB_DIR: /usr/lib/ruby/site_ruby/1.9.1
After changing this variables, press 'c' to configure, then 'g' to generate
the files (ignore any warnings in these steps).

If all the above fails, you may try asking on the qtruby forum
http://rubyforge.org/forum/forum.php?forum_id=722 or the kde-bindings mailing
list (you can subscribe to it at
https://mail.kde.org/mailman/listinfo/kde-bindings\).

By the way, where did you download qtruby from? Maybe the version you
downloaded is not as recent as you thought!

I hope this helps

Stefano

···

On Wednesday 07 December 2011 Rosalind Mitchell wrote

I am running KDE on 32-bit Linux Mint Debian Edition. For several years now
I have been developing Qt-based applications with Ruby 1.8.

Now I'm anxious to move forward and adopt Ruby 1.9 as urged. I can install
1.9.2 from the LMDE repositories, but there doesn't appear to be any Qt4
libraries available. So I thought I'd go right up to date, downloading and
compiling Ruby 1.9.3p0 from scratch, installing it in the /usr/local
hierarchy.

I found, downloaded and extracted the latest Qt4-QtRuby build files. This
is where the headaches began. Running cmake . failed immediately as cmake
could not find Ruby. After scratching my head and searching Google I
established that the CMakeCache.txt file needed some tweaking. To be
precise, these lines needed to be filled out to allow cmake to find the
ruby.h file and ruby executable:

//Path to a file.
RUBY_CONFIG_INCLUDE_DIR:PATH=/usr/local/include/ruby-1.9.1/i686-linux

//Path to a program.
RUBY_EXECUTABLE:FILEPATH=/usr/local/bin/ruby

This, then, allowed me to build and install the Qt4-QtRuby library. But
then, when I went to test it with a very minimal script:

#!/usr/local/bin/ruby -w

require 'Qt4'

app = Qt::Application.new(ARGV)

app.exec()

I get the response:

/usr/local/lib/ruby/site_ruby/1.9.1/Qt/qtruby4.rb:1415: warning: mismatched
indentations at 'end' with 'if' at 1411
/usr/local/lib/ruby/site_ruby/1.9.1/Qt/qtruby4.rb:2527: warning: method
redefined; discarding old method_missing

[...]

/usr/local/lib/ruby/site_ruby/1.9.1/Qt/qtruby4.rb:2527: warning: method
redefined; discarding old const_missing
/usr/local/lib/ruby/site_ruby/1.9.1/Qt/qtruby4.rb:459:in `initialize':
unresolved constructor call Qt::Application (ArgumentError)
        from /usr/local/lib/ruby/site_ruby/1.9.1/Qt/qtruby4.rb:459:in
`initialize'
        from /usr/local/lib/ruby/site_ruby/1.9.1/Qt/qtruby4.rb:2640:in
`call' from /usr/local/lib/ruby/site_ruby/1.9.1/Qt/qtruby4.rb:2640:in
`block in try_initialize'
        from /usr/local/lib/ruby/site_ruby/1.9.1/Qt/qtruby4.rb:2639:in
`catch' from /usr/local/lib/ruby/site_ruby/1.9.1/Qt/qtruby4.rb:2639:in
`try_initialize'
        from ./qt.rb:16:in `new'
        from ./qt.rb:16:in `<main>'

(that second warning repeated several hundred times, though I'm not all that
concerned about that.)

The test script works fine under 1.8.7, obviously it doesn't do anything but
it doesn't throw any warnings or errors either.

Doing the same in irb yields

irb(main):001:0> require 'Qt4'
=> true
irb(main):002:0> app = Qt::Application.new(ARGV)
ArgumentError: unresolved constructor call Qt::Application

        from /usr/local/lib/ruby/site_ruby/1.9.1/Qt/qtruby4.rb:459:in
`initialize'
        from /usr/local/lib/ruby/site_ruby/1.9.1/Qt/qtruby4.rb:459:in
`initialize'
        from /usr/local/lib/ruby/site_ruby/1.9.1/Qt/qtruby4.rb:2640:in
`call' from /usr/local/lib/ruby/site_ruby/1.9.1/Qt/qtruby4.rb:2640:in
`block in try_initialize'
        from /usr/local/lib/ruby/site_ruby/1.9.1/Qt/qtruby4.rb:2639:in
`catch' from /usr/local/lib/ruby/site_ruby/1.9.1/Qt/qtruby4.rb:2639:in
`try_initialize'
        from (irb):2:in `new'
        from (irb):2
        from /usr/local/bin/irb:12:in `<main>'
irb(main):003:0>

Enquiries on Google haven't been very fruitful, with just a suggestion that
the fault lies in the Qt.cpp file but not much help that I could see on
exactly what the problem is or how to fix it (my knowledge of C++ is
sketchy at best).

I have the feeling either that I've missed something very simple, or that
Ruby 1.9.x is not yet able to work effectively with Qt4. Is there anybody
here who has encountered this problem? Should I carry on regardless with
1.9.3 and find another GUI interface to work with, or should I reluctantly
revert to 1.8.7?

Rosie

I cant help you much myself.

I am still on 1.8.7 although lately I have almost managed to upgrade to
1.9.x (I factored out incompatible yaml files with german umlauts. I
don't want to be forced to use UTF-8 just because of Ruby, ISO* is fine
for me. I can't be bothered to must-accept UTF-8).

Unfortunately I don't know if ruby-qt is still active.

Rubyforge of Qt seems to be dead. Where is QT development still
happening? Is rdale still maintaining things?

These kind of things should go into a homepage.

For ruby-gnome, we have a homepage with lots of documentation. Ruby-qt
could use that too.

···

--
Posted via http://www.ruby-forum.com/.

Rubyforge of Qt seems to be dead. Where is QT development still
happening? Is rdale still maintaining things?

It would be a shame, since Ruby and Qt seem made for each other. If only
there could be a more rubyish way of dealing with signals and slots, which is
one of the things I was hoping to find in a more up-to-date QtRuby.

These kind of things should go into a homepage.

Yes.

For ruby-gnome, we have a homepage with lots of documentation. Ruby-qt
could use that too.

I have a horrible feeling that I see a destiny opening up. Not before I've
got it working though. And not on my own – I'm getting much too old for that
sort of thing! Right now I'm setting up a pristine system to see if I can get
Ruby and Qt going without previous baggage.

Meanwhile, thanks for the input.

Roskg

···

On Wednesday 07 Dec 2011 08:54:09 Marc Heiler wrote:

--
Mój poduszkowiec jest pełen węgorzy
Currently reading Headlong by Michael Frayn