[Kde-bindings] Qyoto memory problem

Jordan Miner jminer7 at gmail.com
Thu Feb 14 15:37:42 UTC 2013


Hi,

I'm having a problem that seems like a bug in Qyoto. When I run the
following code, usually (not always) I see a tree with two items under
the root item. When I uncomment the GC.Collect(), one or both of the
items no longer appear. It seems like the sub-items are getting
garbage collected after they are added to the root item, but before
the root item is added to the tree. The root item isn't keeping them
from being collected like it should.

I also ran into another instance of an object being collected when it
shouldn't be, but I'll post it later.

I'm currently using the .NET Framework (not Mono) on Windows XP.

using System;
using System.Collections.Generic;
using QtCore;
using QtGui;

class Test1 : QMainWindow
{
    public Test1()
    {
        QTreeWidget treeWidget = new QTreeWidget();
        QTreeWidgetItem root = new QTreeWidgetItem();
        root.SetData(0, (int)Qt.ItemDataRole.DisplayRole, "Root Item");

        QTreeWidgetItem item = new QTreeWidgetItem();
        item.SetData(0, (int)Qt.ItemDataRole.DisplayRole, "Item #1");
        root.AddChild(item);
        item = new QTreeWidgetItem();
        item.SetData(0, (int)Qt.ItemDataRole.DisplayRole, "Item #2");
        root.AddChild(item);
        //GC.Collect();
        treeWidget.AddTopLevelItem(root);

        CentralWidget = treeWidget;
        Show();
    }

    [STAThread]
    public static int Main(String[] args)
    {
        new QApplication(args);
        new Test1();
        return QApplication.Exec();
    }
}

Thanks,
Jordan


More information about the Kde-bindings mailing list