Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Prevent Destruction of QList<QTreeWidgetItem *>
Qt 6.12 LTS is out! See what's new in the release blog

Prevent Destruction of QList<QTreeWidgetItem *>

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 585 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • webzoidW Offline
    webzoidW Offline
    webzoid
    wrote on last edited by webzoid
    #1

    I'm creating a QList<QTreeWidgetItem *> which holds an INI-backed list of virtual files and folders specified by the end user.

    The problem is that because the items from the QList are associated with a QTreeWidget when presented to the user, they are also destroyed when the QTreeWidget is destroyed.

    Is there any way I can stop this happening?

    I have looked into using a QTreeView but the implementation seems to be pretty horrible and would prefer using the QTreeWidget if it is possible.

    J.HilkJ 1 Reply Last reply
    0
    • webzoidW webzoid

      I'm creating a QList<QTreeWidgetItem *> which holds an INI-backed list of virtual files and folders specified by the end user.

      The problem is that because the items from the QList are associated with a QTreeWidget when presented to the user, they are also destroyed when the QTreeWidget is destroyed.

      Is there any way I can stop this happening?

      I have looked into using a QTreeView but the implementation seems to be pretty horrible and would prefer using the QTreeWidget if it is possible.

      J.HilkJ Offline
      J.HilkJ Offline
      J.Hilk
      Moderators
      wrote on last edited by
      #2

      @webzoid
      in the destructor of your QTreeWidget call takeChildren that should take all items from the widget and return it as a list.
      You can ignore the returned list, as you have one in memory already.

      This is untested, I'm not 100% sure the TreeWidget won't still delete the items.


      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


      Q: What's that?
      A: It's blue light.
      Q: What does it do?
      A: It turns blue.

      1 Reply Last reply
      1
      • webzoidW Offline
        webzoidW Offline
        webzoid
        wrote on last edited by
        #3

        @J-Hilk Thanks for your reply.

        Unfortunately this doesn't work - the items are still munched up by the QTreeWidget.

        I guess I'm just going to have to bite the bullet and figure out how to use a QTreeView.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt
        • Unsolved