[Kde-bindings] Qyoto and QTreeView/QAbstractItemModel: "C# instance has been wrongly GC'd for virtual call"
Arno Rehn
arno at arnorehn.de
Sat Nov 19 13:31:01 UTC 2011
On Friday 18 November 2011 12:06:34 Steven Boswell II wrote:
> I'm using Qyoto and MonoDevelop under Linux to write applications in C# with
> Qt GUIs. I ported TreeItem and TreeModel from the simpletreemodel example
> to C#, and attached a TreeModel to a QTreeView using its SetModel()
> method. But I kept getting low-level crashes in Mono. Sometimes, I would
> get a message: "C# instance has been wrongly GC'd for virtual ... call".
>
> I lucked out finding a workaround; it turns out the data-model was getting
> garbage-collected. I just saved a reference to it in my main class, and
> the problem went away.
>
> It seems to me that anything passed to QTreeView.SetModel() should be
> accounted for within Mono's memory-management system, and not get
> garbage-collected behind its back.
Yes, but that's a little difficult. The setModel() call will not take ownership
of the model, because it might be shared between multiple views (see
http://doc.qt.nokia.com/latest/qabstractitemview.html#setModel
for reference). Without special-casing the setModel() call, we have no way of
knowing whether the model is currently in use or not. But special-casing is
always bad, simply because you might miss a lot of other cases.
Maybe we should simply add the proper workarounds to the wiki or the README.
> I found a post on kde-bindings from June 2009 (see
> http://lists.kde.org/?l=kde-bindings&m=124587984005541 to read it) where
> someone had the same problem, but no one answered his question.
>
> Hope this helps, though it's my understanding that Qyoto's author is no
> longer developing it. That's a shame; Qt and C# seem like a powerful combo
> for cross-platform application development.
Yes, C# and Qt fit very nicely. However, nearly no-one in the *nix world cares
about the whole Mono thing (actually, nearly everyone dislikes it) - so it was
never seriously used by anyone.
--
Arno Rehn
More information about the Kde-bindings
mailing list