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

Arno Rehn arno at arnorehn.de
Wed Dec 22 19:23:48 UTC 2010

On Wednesday 22 December 2010 18:06:36 Alex wrote:
> On Wed, Dec 22, 2010 at 4:28 AM, Arno Rehn <arno at arnorehn.de> wrote:
> > On Wednesday 22 December 2010 04:14:49 Vincent Batts wrote:
> >> from the kdebindings/ruby/qtruby/examples/ check out
> >> ./examples/dialogs/simplewizard/classwizard.rb
> >> ./examples/mainwindows/mdi/mainwindow.rb
> >> they both use QWidget
> >> 
> >> as for QGraphicsItem, i don't think it is available in qtruby yet.
> > 
> > Of course it's available. QtRuby supports nearly all Qt classes.
> > I think Alex' question was a different one anyway.
> Yeah, I have used QGraphicsItem on the ruby side, for prototyping, but
> the ruby side isn't fast enough to do what I want to do so I want to
> use c++ for this custom item.
> >> On Tue, Dec 21, 2010 at 9:55 PM, Alex <x37v.alex at gmail.com> wrote:
> >> > Does anyone have a simple example project where you wrap a qt derived
> >> > class, QWidget or QGraphicsItem, .. and use it on the ruby side with
> >> > qtruby?
> >> > 
> >> > I figure there are a few steps, the smoke wrapping, probably some code
> >> > or tool to do the ruby wrapping, and compiling... but, it is kind of
> >> > unclear to me how people actually do it.
> >> > 
> >> > I have seen a lot of talk of it being possible but I haven't seen any
> >> > actual examples which do it, I figure that would be very useful for a
> >> > number of other folks as well.
> > 
> > If you only have one or two classes to expose, the following might be
> > much easier:
> > http://pcapriotti.wordpress.com/2010/12/06/effective-qt-in-ruby-part-3-2/
> > 
> > But if you instead want to wrap a whole library, the Smoke approach is
> > much better. Docs on how to create a Smoke library can be found here:
> > http://techbase.kde.org/Development/Languages/Smoke
> My understanding is that he is creating just one instance of his
> object and using it as a single 'effect' processor.  I'm looking to
> have an entire class wrapped so i can instantiate it multiple times
> and use it in various places in my GUI.
You could also create a slot like this:

QGraphicsItem* Extensions::createMyGraphicsItem()
	return new MyQGraphicsItem();

where MyQGraphicsItem could be defined like:

class MyQGraphicsItem : public QGraphicsItem
public slots:
	void myNewFancyMethod();

etc. There's nothing stopping you from returning actual objects from your 
extension slot.

> > Looking at existing ones isn't a bad idea either :)
> Yeah, thats basically what I'm looking for, a simple example of doing this.
> > 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..
QtRuby is also released as part of kdebindings. Download the latest tarball 
and take a look at the Ruby bindings in there. There are quite a bunch of 
them, many of which are as simple as what you want to do. I still think for 
only one class it's not worth the effort.

Arno Rehn
arno at arnorehn.de

More information about the Kde-bindings mailing list