[Kde-bindings] Qyoto memory problem

Dimitar Dobrev dpldobrev at yahoo.com
Thu Feb 14 15:57:06 UTC 2013


    

    Hello,

    The Qt docs are a bit vague about whether addChild and similar functions change the ownership of the passed object. However, in the chapter for QTreeWidgetItem they do give the following:

Items are usually constructed with a parent that is either a QTreeWidget (for top-level items) or a QTreeWidgetItem (for items on lower levels of the tree). For example, the following code constructs a top-level item to represent cities of the world, and adds a entry for Oslo as a child item:
QTreeWidgetItem *cities = new QTreeWidgetItem(treeWidget); cities->setText(0, tr("Cities")); QTreeWidgetItem *osloItem = new QTreeWidgetItem(cities); osloItem->setText(0, tr("Oslo")); osloItem->setText(1, tr("Yes"));
    So you may try explicitly giving a parent to your items. I myself will test your example later today.

    Regards,
    Dimitar Dobrev



________________________________
 From: Jordan Miner <jminer7 at gmail.com>
To: kde-bindings at kde.org 
Sent: Thursday, February 14, 2013 5:37 PM
Subject: [Kde-bindings] Qyoto memory problem
 
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
_______________________________________________
Kde-bindings mailing list
Kde-bindings at kde.org
https://mail.kde.org/mailman/listinfo/kde-bindings
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.kde.org/pipermail/kde-bindings/attachments/20130214/c813bef1/attachment.html>


More information about the Kde-bindings mailing list