[Kde-bindings] Re: qtruby: problem communicating ruby-defined objects via properties

Richard Dale richard.dale at telefonica.net
Tue May 31 20:21:07 UTC 2011


On Friday, May 27, 2011 06:50:13 PM Sven Moritz Hallberg wrote:
> hi all,
> 
> here's a problem i'm experiencing with my qtruby property patch posted
> before. hopefully someone can shed some light on what's to blame here.
> 
> in the attached program, i define and instantiate two custom descendants of
> Qt::Object. one contains the other in a property. the QML side tries to
> extract the value of the property and call a slot on the object.
> unfortunately it never gets that far because the value it gets from the
> property is not translated to a Javascript object.
> 
> for comparison it exports the object directly first.
> 
> expected output:
> [qml] bar = Bar(0x...)
> [qml] calling bar.baz(123)
> [ruby] in baz: got 123.0
> [qml] foo.bar = Bar(0x...)
> [qml] calling foo.bar.baz(123)
> [ruby] in baz: got 123.0
> 
> actual output:
> [qml] bar = Bar(0x206ec10)
> [qml] calling bar.baz(123)
> [ruby] in baz: got 123.0
> [qml] foo.bar = QVariant(rObject)
> [qml] calling foo.bar.baz(123)
> file:///home/hallberg/test/qt2a.qml:13: TypeError: Result of expression
> 'foo.bar.baz' [undefined] is not a function.
> 
> note foo.bar being printed as QVariant(rObject) instead of Bar.
I think it needs to be exposed as a QObject or maybe a QObject wrapped inside 
a QVariant. The QML runtime doesn't know anything about about rObjects.

I've been studying the property changes for most of today, and i still haven't 
quite thought it all through. I'm not sure that we need to have READ and WRITE 
method names. I had thought they were somewhere inside the QMetaObject, but 
they're not. 

So this code that calls the Ruby method qt_readprop() to get the value doesn't 
go via the QMetaObject containing the properties, but instead uses the Ruby 
data structures that were used to build the QMetaObject.

	else if (_c == QMetaObject::ReadProperty) {
		VALUE variant = rb_funcall(self, rb_intern("qt_readprop"), 1, 
argv[1]);
		smokeruby_object *smoke_variant = value_obj_info(variant);
		_o[0] = smoke_variant->ptr;
	}

So as the READ and WRITE method names aren't in the QMetaObject I would prefer 
that we always call them as 'prop' and 'prop=', and then the code in 
qt_metacall() wouldn't need to call qt_readprop() and qt_writeprop().

-- Richard

> any help?
> 
> TIA!
> Sven



More information about the Kde-bindings mailing list