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. Ensure garbage collection on QListWidget items.
Qt 6.11 is out! See what's new in the release blog

Ensure garbage collection on QListWidget items.

Scheduled Pinned Locked Moved Solved General and Desktop
2 Posts 2 Posters 435 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
    teux
    wrote on last edited by teux
    #1

    Does QListWidget::clear() delete all dynamically allocated elements it contains in Qt4.8? I'm not sure how to interpret the documentation, and I want to ensure I'm doing this properly.

    I populate my list with custom QWidget HistoryItem as shown:

        HistoryItem *historyItem = new HistoryItem(this, ...some data parameters...);
        QListWidgetItem *qlwItem = new QListWidgetItem();
        qlwItem->setSizeHint(QSize(0, 70));
        ui->listWidget->addItem(qlwItem);
        ui->listWidget->setItemWidget(qlwItem, historyItem);
    

    I'm not worried about the HistoryItems as they get a pointer to the parent QWidget. But the QListWidgetItems don't have that. If they're not deleted with QListWidget::clear(), can I use QListWidget::itemFromIndex() to get the pointers for deletion? Is that the correct procedure?

    Thank you for the help.

    And I know 4.8 is OLD. (Sorry!) Porting to 5 will happen in the future, but it's not feasible at the moment for toolchain and time reasons.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      As the warning state, all items are deleted.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      2

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved