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

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

XMLWordPrintable

    • All
    • 089d54f06ff327f5212cb08fdbcb540066357dd5 (qt/qtbase/dev)

      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

        For Gerrit Dashboard: QTBUG-72483
        # Subject Branch Project Status CR V

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

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes