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. QListWidget::clear() effect on pointers

QListWidget::clear() effect on pointers

Scheduled Pinned Locked Moved General and Desktop
6 Posts 4 Posters 5.3k 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.
  • T Offline
    T Offline
    TheDestroyer
    wrote on last edited by
    #1

    I have a small question which I'm asking just to be on the safe side with memory management.

    I have added some QListWidgetItems' pointers to a QListWidget (of course after initialising them with a "new" operator). Now the question is, does the function QListWidget::clear() automatically call the operator delete on the pointers added to the list? The documentation was a little bit vague, since it doesn't say that explicitly. I'm confused whether the delete they meant is just remove items from the list.

    Thanks :-)

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

      If the docs are unclear, see the source!

      http://qt.gitorious.org/qt/qt/blobs/4.8/src/gui/itemviews/qlistwidget.cpp#line1753
      http://qt.gitorious.org/qt/qt/blobs/4.8/src/gui/itemviews/qlistwidget.cpp#line76

      Software Engineer
      KDAB (UK) Ltd., a KDAB Group company

      1 Reply Last reply
      0
      • G Offline
        G Offline
        goetz
        wrote on last edited by
        #3

        I would say the docs are quite clear here:

        bq. "void QListWidget::clear () [slot]":/doc/qt-4.8/qlistwidget.html#clear
        Removes all items and selections in the view.
        Warning: All items will be permanently deleted.

        http://www.catb.org/~esr/faqs/smart-questions.html

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

          In that same page:http://developper.qt.nokia.com/doc/qlistwidget.html it is stated:
          [quote]The list widget will take ownership of the item.[/quote]
          Taking ownership means that the class will manage the life time of the items you set on it. If in doubt, it helps to search for the term ownership on the documentation page.

          @Volker: your link does not work for me?

          1 Reply Last reply
          0
          • G Offline
            G Offline
            goetz
            wrote on last edited by
            #5

            [quote author="Andre" date="1330326445"]
            @Volker: your link does not work for me?[/quote]

            I missed a leading slash. Fixed now - thanks for pointing out.

            http://www.catb.org/~esr/faqs/smart-questions.html

            1 Reply Last reply
            0
            • T Offline
              T Offline
              TheDestroyer
              wrote on last edited by
              #6

              I was 90% sure, since I called the delete operator and the program crashed, and now I'm 100% sure.

              Thanks :-)

              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