Important: Please read the Qt Code of Conduct -

QList<QLabel *> static or dynamic?

  • I use QList<QLabel *> list as a class member.
    I'm gonna add and remove elements in it, so shall I create it statically or dynamically?

  • bq. so shall I create it statically or dynamically?

    I don't get the point. Could you explain a little bit more ?

  • Ecxuse me)
    I mean, shall I declare class member QList<QLabel *> * list and use operator new to create list, or shall I just declare QList<QLabel *> list and work with it (work == add and remove items in class member list)?

    p.s. if not clear, give notice.

  • Definitively, keep working with a single QList, as it is. You don't need a pointer here.

    As a general rule, don't use pointers with classes like QList, QString, QByteArray, except if you REALLY need it.

    It just works ouf of the box, and then you prevent yourself from memory leaks. A pointer to a QList needs to be explicitely deleted, since it doesn't have a QObject parent.

  • Indeed, you probably don't need the list itself to be on the heap. Just make it a member of your class.

  • great. thank you for your replies.)

Log in to reply