Qt::UiLoader -> uninitialized constant Qt::QUiLoader

Hi,

using 1.9.2p0 and qtbindings (4.6.3.0) I always get

$ ruby -rQt -e 'Qt::UiLoader.new'
-e:1:in `const_missing': uninitialized constant Qt::UiLoader (NameError)
  from -e:1:in `<main>'

According to


it should be there.

I'm wondering what I'm missing ... ?

I can use the generate rbuic4 but I'm more looking into loading it at
runtime.

thanks,
- Markus

I don't know whether that page is up to date with the latest changes in
qtruby. I don't know which version of qtruby you're using (the 4.6.3 you
mention is the Qt version, not the qtruby version). At any rate, using the
version I have installed, which is the one included with KDE 4.5.1, I have to
require qtuitools besides Qt:

require 'Qt'
require 'qtuitools'

app = Qt::Application.new []
ui = Qt::UiLoader.new

I hope this helps

Stefano

···

On Sunday 26 September 2010, Markus Fischer wrote:

>Hi,
>
>using 1.9.2p0 and qtbindings (4.6.3.0) I always get
>
>$ ruby -rQt -e 'Qt::UiLoader.new'
>-e:1:in `const_missing': uninitialized constant Qt::UiLoader (NameError)
> from -e:1:in `<main>'
>
>According to
>http://github.com/ryanmelt/qtbindings/blob/master/ext/ruby/qtruby/README#L
>224 it should be there.
>
>I'm wondering what I'm missing ... ?
>
>I can use the generate rbuic4 but I'm more looking into loading it at
>runtime.
>
>thanks,
>- Markus

Hi,

require 'Qt'
require 'qtuitools'

app = Qt::Application.new []
ui = Qt::UiLoader.new

That helps a bit! I'm only one step further however:

$ irb
ruby-1.9.2-p0 > require 'Qt'
=> true
ruby-1.9.2-p0 > require 'qtuitools'
=> true
ruby-1.9.2-p0 >
ruby-1.9.2-p0 > app = Qt::Application.new []
=> #<Qt::Application:0x000000026b7590 objectName="irb">
ruby-1.9.2-p0 > ui = Qt::UiLoader.new
=> #<Qt::UiLoader:0x000000026a81a8 objectName="">
ruby-1.9.2-p0 > ui.load
NoMethodError: private method `load' called for
#<Qt::UiLoader:0x000000026a81a8 objectName="">
  from (irb):6:in `method_missing'
  from (irb):6
  from /home/mfischer/.rvm/rubies/ruby-1.9.2-p0/bin/irb:17:in `<main>'

It's a bit hard currently to not get lost with these different QT ruby
ports.

So there's the qtruby4 gem which only contains binaries for mswin32 (and
it's not mingw32, either). If you want qtruby4 anywhere else, manual
source compilation is required.

Then we've the gem "qtbindings" which attempts to address the
shortcoming of qtruby4 not available on non-windows platforms, which is
fairly new and which I'm using.

Sometimes skimming through the docs I also find references to korundum
(e.g. http://rubyforge.org/projects/korundum/ ) which I've no clue what
it is.

Is the rubyforge project related to the qtruby4 gem or is it something
different?

That's all really confusing.

Stefano: if I may ask, in which environment are you developing?

thanks,
- Markus

···

On 26.09.2010 22:50, Stefano Crocco wrote:

>Hi,
>
>> require 'Qt'
>> require 'qtuitools'
>>
>> app = Qt::Application.new []
>> ui = Qt::UiLoader.new
>
>That helps a bit! I'm only one step further however:
>
>$ irb
>ruby-1.9.2-p0 > require 'Qt'
> => true
>ruby-1.9.2-p0 > require 'qtuitools'
> => true
>ruby-1.9.2-p0 >
>ruby-1.9.2-p0 > app = Qt::Application.new []
> => #<Qt::Application:0x000000026b7590 objectName="irb">
>ruby-1.9.2-p0 > ui = Qt::UiLoader.new
> => #<Qt::UiLoader:0x000000026a81a8 objectName="">
>ruby-1.9.2-p0 > ui.load
>NoMethodError: private method `load' called for
>#<Qt::UiLoader:0x000000026a81a8 objectName="">
> from (irb):6:in `method_missing'
> from (irb):6
> from /home/mfischer/.rvm/rubies/ruby-1.9.2-p0/bin/irb:17:in `<main>'

You're calling the load method with the wrong arguments. I think that, due to
the way the qt bindings work, this ends up calling Kernel#load, which is a
private method and therefore can't be called with a receiver. To have your
code work, you just need to follow the example you posted in your previous
mail:

require 'Qt'
require 'qtuitools'
app = Qt::Application.new []
loader = Qt::UiLoader.new
#Create a file pointing to the .ui file you want to load. Unfortunately, you
#can't use a ruby file here
file = Qt::File.new '/path/to/ui/file.ui'
#open the file
file.open Qt::File::ReadOnly
#At last, load the ui file. If the widget contained in the ui file should be
#a child of another widget, pass that widget as secon argument instead of nil
widget = loader.load file, nil
#Close the file
file.close
#Now do whatever you like with the widget. For example,
widget.show
app.exec

>It's a bit hard currently to not get lost with these different QT ruby
>ports.
>
>So there's the qtruby4 gem which only contains binaries for mswin32 (and
>it's not mingw32, either). If you want qtruby4 anywhere else, manual
>source compilation is required.
>
>Then we've the gem "qtbindings" which attempts to address the
>shortcoming of qtruby4 not available on non-windows platforms, which is
>fairly new and which I'm using.
>
>Sometimes skimming through the docs I also find references to korundum
>(e.g. http://rubyforge.org/projects/korundum/ ) which I've no clue what
>it is.
>
>Is the rubyforge project related to the qtruby4 gem or is it something
>different?
>
>That's all really confusing.

Actually, there's only one qt ruby bindings. The situation is the following.
The Qt ruby bindings have been born as a part of the ruby bindings for KDE (in
case you don't know, KDE is a desktop environment born for Linux and based on
the Qt libraries). This is "korundum".

Since KDE is based on Qt, korundum also contains bindings for all of the Qt
classes, so the developers decided to allow users who don't have KDE to
install only the parts of korundum containing the bindings to Qt. This is Qt
ruby (or qtruby).

Originally, the build system of qtruby was the same as the KDE one, based on
the cmake utility. This wasn't very easy, expecially on windows (this also
happened because new releases of qtruby weren't released very often, so to
obtain a newer version, you often needed to start from the korundum sources
and modify the build system to remove anythig related to KDE before starting
compiling). To make things easier for windows users, a windows binary gem of
qtruby was created and called qtruby4.

Now, it seems, the korundum developers have decided to create a proper gem for
qtruby, which is what you're using. I can't say much on this, as I didn't know
about it until I read your mail

>Stefano: if I may ask, in which environment are you developing?

I'm using the ruby bindings for KDE (that is, korundum) on gentoo linux

>thanks,
>- Markus

I hope this helps

Stefano

···

On Sunday 26 September 2010, Markus Fischer wrote:

>On 26.09.2010 22:50, Stefano Crocco wrote: