Nominate our 2022 Qt Champions!

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

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

    QList <CustomClass > lines; //Declaration.
    //Call to remove:

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



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

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

  • Ty 1 +1 for your fast reply.

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

Log in to reply