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. QList<QLabel *> static or dynamic?
Forum Updated to NodeBB v4.3 + New Features

QList<QLabel *> static or dynamic?

Scheduled Pinned Locked Moved General and Desktop
6 Posts 3 Posters 5.4k 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.
  • B Offline
    B Offline
    bright day
    wrote on last edited by
    #1

    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?

    1 Reply Last reply
    0
    • O Offline
      O Offline
      octal
      wrote on last edited by
      #2

      bq. so shall I create it statically or dynamically?

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

      1 Reply Last reply
      0
      • B Offline
        B Offline
        bright day
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0
        • O Offline
          O Offline
          octal
          wrote on last edited by
          #4

          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.

          1 Reply Last reply
          0
          • A Offline
            A Offline
            andre
            wrote on last edited by
            #5

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

            1 Reply Last reply
            0
            • B Offline
              B Offline
              bright day
              wrote on last edited by
              #6

              great. thank you for your replies.)

              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