[Kde-bindings] Re: Custom properties on QObjects defined in qtruby

Arno Rehn arno at arnorehn.de
Tue Apr 12 15:24:42 UTC 2011


On Tuesday 12 April 2011 16:10:09 Sven Moritz Hallberg wrote:
> On 04/07/2011 09:16 PM, Sven Moritz Hallberg wrote:
> > As far as I can tell, I need to catch a
> > 
> >     qt_metacall(ReadProperty, ...)
> > 
> > somewhere and let it dispatch to the given READ function. Is that right?
> > I just can't see where or how.
> 
> OK, I've added the following to qt_metacall in src/qtruby.cpp:
> 
>     if (_c == QMetaObject::ReadProperty) {
>         argv[2] = rb_funcall(self, rb_intern("qt_readprop"), 2, argv[1]);
>         return INT2NUM(-1);
>     }
> 
> The function qt_readprop I defined in class Base and it just finds and
> calls the READ function for the requested property. That works. My
> function is called every time something tries to read the property and it
> returns the value to C++. What I can't figure out is how to communicate
> that result back to Qt land... As you can see, I've tried simply assigning
> to argv[2] above, but that seems to have no effect. Is there some kind of
> marshalling magic I need to invoke? Maybe someone has a tip here...
Yes, you have to assign the property value to _o[0] (_o is the pointer array 
that you get from argv[2] at the beginning of the function).

qt_readprop should already return a Qt::Variant. In C++, you now have to 
extact the pointer to the underlying QVariant and assign that to _o[0].

You probably have include some checks whether the property does really exist 
and whether you should actually handle it (I guess our current C# code doesn't 
check for this, too, or maybe it does in some implicit way that I didn't 
discover yet).

If you haven't found it already, here's the relevant C++ code from the C# 
bindings:

https://projects.kde.org/projects/kde/kdebindings/csharp/qyoto/repository/revisions/master/entry/src/qobject_interop.cpp#L373

-- 
Arno Rehn
arno at arnorehn.de



More information about the Kde-bindings mailing list