From: Stefano Crocco Date: 2010-09-27T15:57:20+09:00 Subject: Re: NoMethodError: private method `load' called for Qt::UiLoader (was: Re: Qt::UiLoader -> uninitialized constant Qt::QUiLoader) On Sunday 26 September 2010, Markus Fischer wrote: > |Hi, > | > |On 26.09.2010 22:50, Stefano Crocco wrote: > |> 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 [] > | => # > |ruby-1.9.2-p0 > ui = Qt::UiLoader.new > | => # > |ruby-1.9.2-p0 > ui.load > |NoMethodError: private method `load' called for > |# > | from (irb):6:in `method_missing' > | from (irb):6 > | from /home/mfischer/.rvm/rubies/ruby-1.9.2-p0/bin/irb:17:in `
' 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