<html><body><div style="color:#000; background-color:#fff; font-family:times new roman, new york, times, serif;font-size:12pt"><span class="tab">    <br></span><div style="color: rgb(0, 0, 0); font-size: 16px; font-family: times new roman,new york,times,serif; background-color: transparent; font-style: normal;"><span class="tab">    Hello,</span></div><div style="color: rgb(0, 0, 0); font-size: 16px; font-family: times new roman,new york,times,serif; background-color: transparent; font-style: normal;"><br><span class="tab"></span></div><div style="color: rgb(0, 0, 0); font-size: 16px; font-family: times new roman,new york,times,serif; background-color: transparent; font-style: normal;"><span class="tab">    The Qt docs are a bit vague </span><span class="tab"></span>about whether addChild and similar functions change the ownership of the passed object. However, in the chapter for QTreeWidgetItem they do
 give the following:</div><div style="color: rgb(0, 0, 0); font-size: 16px; font-family: times new roman,new york,times,serif; background-color: transparent; font-style: normal;"><br></div><div style="color: rgb(0, 0, 0); font-size: 16px; font-family: times new roman,new york,times,serif; background-color: transparent; font-style: normal;"><span class="Apple-style-span" style="border-collapse: separate; color: rgb(49, 49, 49); font-family: Arial, Helvetica; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 16px; orphans: 2; text-align: justify; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; "><div>Items are usually constructed with a parent that is either a<span
 class="Apple-converted-space"> </span><a href="qthelp://com.trolltech.qt.484/qdoc/qtreewidget.html" style="color: rgb(44, 65, 141); text-decoration: none; text-align: left; ">QTreeWidget</a><span class="Apple-converted-space"> </span>(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:</div><pre class="cpp" style="border-top-left-radius: 7px 7px; border-top-right-radius: 7px 7px; border-bottom-right-radius: 7px 7px; border-bottom-left-radius: 7px 7px; background-color: rgb(246, 246, 246); border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: rgb(230, 230, 230); border-right-color: rgb(230, 230, 230);
 border-bottom-color: rgb(230, 230, 230); border-left-color: rgb(230, 230, 230); border-collapse: separate; font-size: 12px; line-height: 1.2; margin-bottom: 25px; margin-left: 15px; display: block; overflow-x: hidden; overflow-y: hidden; padding-top: 20px; padding-right: 0px; padding-bottom: 20px; padding-left: 0px; ">     <span class="type" style="color: rgb(128, 128, 128); ">QTreeWidgetItem</span> <span class="operator">*</span>cities <span class="operator">=</span> <span class="keyword">new</span> <span class="type" style="color: rgb(128, 128, 128); ">QTreeWidgetItem</span>(treeWidget);
     cities<span class="operator">-</span><span class="operator">></span>setText(<span class="number">0</span><span class="operator">,</span> tr(<span class="string">"Cities"</span>));
     <span class="type" style="color: rgb(128, 128, 128); ">QTreeWidgetItem</span> <span class="operator">*</span>osloItem <span class="operator">=</span> <span class="keyword">new</span> <span class="type" style="color: rgb(128, 128, 128); ">QTreeWidgetItem</span>(cities);
     osloItem<span class="operator">-</span><span class="operator">></span>setText(<span class="number">0</span><span class="operator">,</span> tr(<span class="string">"Oslo"</span>));
     osloItem<span class="operator">-</span><span class="operator">></span>setText(<span class="number">1</span><span class="operator">,</span> tr(<span class="string">"Yes"</span>));</pre></span></div><div style="color: rgb(0, 0, 0); font-size: 16px; font-family: times new roman,new york,times,serif; background-color: transparent; font-style: normal;"><span class="tab">    </span>So you may try explicitly giving a parent to your items. I myself will test your example later today.</div><div style="color: rgb(0, 0, 0); font-size: 16px; font-family: times new roman,new york,times,serif; background-color: transparent; font-style: normal;"><br></div><div style="color: rgb(0, 0, 0); font-size: 16px; font-family: times new roman,new york,times,serif; background-color: transparent; font-style: normal;"><span class="tab">    Regards,</span></div><div style="color: rgb(0, 0, 0); font-size: 16px; font-family: times new roman,new
 york,times,serif; background-color: transparent; font-style: normal;"><span class="tab">    Dimitar Dobrev</span><span class="tab"><br></span></div><div><br></div>  <div style="font-family: times new roman, new york, times, serif; font-size: 12pt;"> <div style="font-family: times new roman, new york, times, serif; font-size: 12pt;"> <div dir="ltr"> <font face="Arial" size="2"> <hr size="1">  <b><span style="font-weight:bold;">From:</span></b> Jordan Miner <jminer7@gmail.com><br> <b><span style="font-weight: bold;">To:</span></b> kde-bindings@kde.org <br> <b><span style="font-weight: bold;">Sent:</span></b> Thursday, February 14, 2013 5:37 PM<br> <b><span style="font-weight: bold;">Subject:</span></b> [Kde-bindings] Qyoto memory problem<br> </font> </div> <br>
Hi,<br><br>I'm having a problem that seems like a bug in Qyoto. When I run the<br>following code, usually (not always) I see a tree with two items under<br>the root item. When I uncomment the GC.Collect(), one or both of the<br>items no longer appear. It seems like the sub-items are getting<br>garbage collected after they are added to the root item, but before<br>the root item is added to the tree. The root item isn't keeping them<br>from being collected like it should.<br><br>I also ran into another instance of an object being collected when it<br>shouldn't be, but I'll post it later.<br><br>I'm currently using the .NET Framework (not Mono) on Windows XP.<br><br>using System;<br>using System.Collections.Generic;<br>using QtCore;<br>using QtGui;<br><br>class Test1 : QMainWindow<br>{<br>    public Test1()<br>    {<br>        QTreeWidget treeWidget = new QTreeWidget();<br>        QTreeWidgetItem
 root = new QTreeWidgetItem();<br>        root.SetData(0, (int)Qt.ItemDataRole.DisplayRole, "Root Item");<br><br>        QTreeWidgetItem item = new QTreeWidgetItem();<br>        item.SetData(0, (int)Qt.ItemDataRole.DisplayRole, "Item #1");<br>        root.AddChild(item);<br>        item = new QTreeWidgetItem();<br>        item.SetData(0, (int)Qt.ItemDataRole.DisplayRole, "Item #2");<br>        root.AddChild(item);<br>        //GC.Collect();<br>        treeWidget.AddTopLevelItem(root);<br><br>        CentralWidget = treeWidget;<br>        Show();<br>    }<br><br>    [STAThread]<br>    public static int Main(String[] args)<br>    {<br>        new QApplication(args);<br> 
       new Test1();<br>        return QApplication.Exec();<br>    }<br>}<br><br>Thanks,<br>Jordan<br>_______________________________________________<br>Kde-bindings mailing list<br><a ymailto="mailto:Kde-bindings@kde.org" href="mailto:Kde-bindings@kde.org">Kde-bindings@kde.org</a><br><a href="https://mail.kde.org/mailman/listinfo/kde-bindings" target="_blank">https://mail.kde.org/mailman/listinfo/kde-bindings</a><br><br><br> </div> </div>  </div></body></html>