[Kde-bindings] Re: custom qt derived c++ class example for qtruby

Ian Monroe ian at monroe.nu
Wed Dec 22 19:16:05 UTC 2010

On Wed, Dec 22, 2010 at 12:12, Alexander Duda <Alexander.Duda at dfki.de> wrote:
> Am 22.12.2010 um 18:06 schrieb Alex:
>>> You still need to create a ruby extension to tell QtRuby to actually load that
>>> additional Smoke library. That's fairly easy, just look at some of the simple
>>> extensions in the QtRuby source (Phonon for example). If you have more
>>> questions, don't hesitate to ask! :)
>> I don't seem to see phonon in the qt ruby source.  I'm using the gem
>> 'qtbindings' but referencing the source qt4-qtruby-2.1.0 to try to
>> find examples.  I don't even see a download for phonon on the phonon
>> page..
> An other way to get access to your qt derived c++ class is using slots and the qt plugin loader (see example below or http://doc.qt.nokia.com/stable/qpluginloader.html). After loading the plugin you have full access to all slots of your class on the ruby side without the need of user specific bindings.
> def load_widget_factory(path)
>    loader = Qt::PluginLoader.new(path)
>    loader.load
>    if !loader.isLoaded
>      puts "Cannot load #{path}. Last error is: #{loader.errorString}"
>      return nil
>    end
>    factory_instance = loader.instance
>    if factory_instance == nil
>      puts "Could not load widget plugin #{loader.fileName}. Last error is: #{loader.errorString}"
>      return nil
>    end
>    factory_instance
> end

Yet another way would be to use the QtScript api. It has lots of
facilities for revealing C++ objects in QtScript, and then you could
access it from QtRuby indirectly that way. But that'd be a big hack, I
like Alexander's way better. :)


More information about the Kde-bindings mailing list