[Kde-bindings] A sample of our subset of QtC
Adam Treat
manyoso at yahoo.com
Sat Jan 11 13:44:23 UTC 2003
On Saturday 11 January 2003 08:17 am, Richard Dale wrote:
> On Saturday 11 January 2003 12:03 pm, Joseph Wenninger wrote:
> > For .Net/Mono/pnet you have to track both, the managed and the reall c++
> > object to be able to handle repartending of widgets (eg
> > QWidget::reparent) and derived classes correctly, without risking that
> > one of them gets deleted by the garbage collector, that's what Adam
> > tries to do with the managedObject void* pointer. It makes things easier
>
> I'm having trouble following the C# talk about garbage collection issues
> because the CLI has its own terms for things.
>
> Anyway, heres how the QtJava memory management works, and why I don't have
> a problem with re-parenting widgets:
What you've just described is exactly what we are doing with the Qt# bindings
_right now_. In fact we took the design pattern from QtJava (to be honest
almost all of Qt# was taken from the example provided by QtJava and QtC, to
which we are greatly indebted ;), but it is overly complicated and I think
we've found a way to make it more elegant and less complicated in our next
release.
Basically, in our next release the Qt# class and it's corresponding QtC glue
class will hold references to each other. The QtC glue class will be
primarily responsible for the lifetime of the Qt# class .. ie, the QtC class
will call the Qt# Dispose method in it's dtor.
Holding a reference to the Qt# class in the glue is also useful for how we
plan to override virtual methods. Basically, if we override a virtual method
in C# the glue will have to call the C# method and pass the arguments (many
of which will be QObjects) and we need a way to automatically wrap those
without having to go through yet another proxy method that'll do the
wrapping. The solution: store a managed reference and let the C# marshalling
magic do the work. It results in a very elegant solution because in C# we
can override operators including implicit/explicit conversion.
Another advantage is to get rid of the Hashtable and all the overhead that
implies.
Cheers,
Adam
More information about the Kde-bindings
mailing list