Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [Solved] Should call destructor after QList<CustomObjectPointer *> when call "remove" methods?
Qt 6.11 is out! See what's new in the release blog

[Solved] Should call destructor after QList<CustomObjectPointer *> when call "remove" methods?

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 1.2k Views 1 Watching
  • 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.
  • R Offline
    R Offline
    Rhadel
    wrote on last edited by
    #1

    If we have a QList managing pointers to custom objects class, when we call remove methods:

    @
    QList <CustomClass > lines; //Declaration.
    /
    ******************/
    //Call to remove:
    lines.removeLast();
    @

    Should I call delete(object Im going to remove) before call lines.removeLast(), or It's called automatically when removeLast() is invoked?

    Ty

    -----------------------EDIT------------------------

    Yes, It's necessary. Otherwise, parent item will still drawing it, if it's a customized QGraphicsItem.

    1 Reply Last reply
    0
    • D Offline
      D Offline
      dbzhang800
      wrote on last edited by
      #2

      Hi, seems takeLast is more suitable for you.
      @
      delete lines.takeLast();
      @

      1 Reply Last reply
      0
      • R Offline
        R Offline
        Rhadel
        wrote on last edited by
        #3

        Ty 1 +1 for your fast reply.

        Your suggestion is much cleaner than mine, thank you =)

        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 Extensions
        • Unsolved