Problems with Open-Source Downloads read and

What is the proper way to rebuild QTreeWidget hierachy

  • In my application I need to be able to rebuild QTreeWidget hierarchy. Conceptually, I need to remove all tree nodes following some number of top level nodes and then add their replacements. I am confused how I need to use existing APIs to do the removal in order to achieve what I need.

    I started by coding something like
    @for( QTreeWidgetItem * item = tree.topLevelItem(3); item != nullptr; item = tree.topLevelItem(3) )
    but quickly discovered that this loop never terminates. Subsequently I replaced the code with
    @for( QTreeWidgetItem * item = tree.takeTopLevelItem(3); item != nullptr; item = tree.takeTopLevelItem(3) )
    delete item;
    This seems to produce desired effects on the screen. Can someone confirm that (a) this is a way I am expected to do it and (b) I am expected to delete no longer needed QTreeWidgetItems myself.

Log in to reply