Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-72483

QComboBox::setItemDelegate() does not take ownership as stated in documenation.

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P3: Somewhat important
    • Resolution: Done
    • Affects Version/s: 5.11.2
    • Fix Version/s: None
    • Component/s: Widgets: Itemviews
    • Labels:
    • Platform/s:
      All
    • Commits:
      089d54f06ff327f5212cb08fdbcb540066357dd5 (qt/qtbase/dev)

      Description

      It could be that I misunderstand the documentation, but for QComboBox::setItemDelegate() the documentation states:

      Sets the item delegate for the popup list view. The combobox takes ownership of the delegate.

      Now, I had the following code result in memory leaks:

      if (const auto comboBox = qobject_cast<QComboBox *>(widget))

      { comboBox->setItemDelegate(std::make_unique<QStyledItemDelegate>().release()); }

      It's easily fixed of course. I can pass the comboBox variable to the constructor of the QStyledItemDelegate to serve as its parent QObject.

      However, I thought I'd mention it anyway. To me it seems like the documentation is wrong about the QComboBox taking ownership of the delegate.

      Regards, Arjen

        Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

            Assignee:
            chehrlic Christian Ehrlicher
            Reporter:
            arjen Arjen Hoogesteger
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:

                Gerrit Reviews

                There are no open Gerrit changes