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

Sven Moritz Hallberg hallberg at pre-sense.de
Thu May 19 13:25:43 UTC 2011


On 04/14/2011 10:09 PM, Sven Moritz Hallberg wrote:
> i've still got a bug here where setting the QVariant property from ruby
> doesn't work. it looks like it's some unpacking issue with the Qt::Variants.
> i.e. as if something looks at the types in
> 
>     dings.setProperty("stuff", Qt::Variant.new("test"))
> 
> and doesn't call qt_metacall because it's expecting to see something of the form
> 
>     Qt::Variant.new(Qt::Variant.new("test"))
> 
> but i can't pass that because the constructor avoids nesting.

sorry for the long silence, some other priorities intervened...
i'm attaching my current patch against the latest qtruby from git
along with a test program that exhibits some problems i can't track down. it
defines a class with two properties, one of type QString, another of QVariant.
it tries to assign values to these in a variety of ways and to read them back
in various ways. it SHOULD print the series of test strings going from "test1"
to "test5" twice, interleaved with some diagnostics in parenthesis. like this:

    (blablabla)
    "test1"
    (blablabla)
    "test2"
    .
    .
    .
    "test5"
    (blablabla)
    "test1"
    .
    .
    .
    "test5"

this is the actual output:

    (initial value "test1")
    "test1"
    (writing "test2" -> true)
    "test2"
    (setting "test3" -> true)
    "test3"
    (assigning "test5")
    "test5"
    (initial value "test1")
    "test1"
    (writing "test2" -> false)
    "test1"
    (setting "test3" -> false)
    "test1"
    (Foo#changeProp(#<Qt::Variant:0x7f983abb1fa0 typeName=QString>))
    (Foo#changeProp("test4"))
    (setting "test4" -> nil)
    "test4"
    /usr/local/lib/site_ruby/1.8/Qt/qtruby4.rb:2435: [BUG] Segmentation fault
    ruby 1.8.7 (2010-06-23 patchlevel 299) [x86_64-linux]

    Aborted

"test4" is missing from the first run because i commented it out. left in, it
produces some memory error from glibc:

    (setting "test3" -> true)
    "test3"
    (setting "test4" -> nil)
    qt3.rb:43: undefined method `value' for "test4":String (NoMethodError)
    *** glibc detected *** ruby: free(): invalid pointer: 0x00007fff54bd2cb0 ***

the next obvious problem is the segfault after "test4" in the second run. i
have a stack trace from gdb and it points to where the 'qt_writeprop' function
extracts the value from the passed QVariant.

actually, these are just annoyances, though, that i encountered on the way
trying to nail down an actual usage problem: i can't assign to the QVariant
property through the metacall facility:

    (initial value "test1")
    "test1"
    (writing "test2" -> false)
    "test1"
    (setting "test3" -> false)
    "test1"

note that it works with the QString property. also note that when reading the
QVariant property via meta calls, i do get a Qt::Variant wrapped in a
Qt::Variant (contrary to what Qt::Variant.new will allow). cf. occurances of
".value.value" in the code.

there is definately something weird going on with these Variants, i just can't
put my finger on it. and it is a problem on the ruby side of things: writing
and assigning the QVariant property from a QML test program works flawlessly.

oomph, sorry for the wall of text!


-Sven

PS. technically, the patch is (c) my employer. alas, we'd very much like to
see it upstream, so it goes as "do what you want, no warranties". ;)

PPS. seeing that work has started on a new version of qtruby, which i haven't
had time to look at, yet, i hope this can be ported over!

-- 
Sven Moritz Hallberg                      hallberg at pre-sense.de
                                  Tel. +49 - 40 - 244 2407 - 28
                                  Fax  +49 - 40 - 244 2407 - 24
PRESENSE Technologies GmbH            Sachsenstr. 5, D-20097 HH
                                         USt-IdNr.: DE263765024
Geschäftsführer/Managing Directors       AG Hamburg, HRB 107844
Till Dörges           Jürgen Sander              Axel Theilmann
-------------- next part --------------
A non-text attachment was scrubbed...
Name: qtruby-properties-2011-05-19.patch
Type: text/x-patch
Size: 10818 bytes
Desc: not available
URL: <http://mail.kde.org/pipermail/kde-bindings/attachments/20110519/8f9a8404/attachment.patch>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: qt3.rb
Type: application/x-ruby
Size: 1812 bytes
Desc: not available
URL: <http://mail.kde.org/pipermail/kde-bindings/attachments/20110519/8f9a8404/attachment.bin>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: stacktrace.txt
URL: <http://mail.kde.org/pipermail/kde-bindings/attachments/20110519/8f9a8404/attachment.txt>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 262 bytes
Desc: OpenPGP digital signature
URL: <http://mail.kde.org/pipermail/kde-bindings/attachments/20110519/8f9a8404/attachment.sig>


More information about the Kde-bindings mailing list