tst_QAbstractItemView: fix memleaks in testDelegateDestroyEditorChild()
After removing the QTreeWidgetItems from the QTreeWidget, they have no parent anymore, and so no-one deletes them and they're leaked. Add a vector<unique_ptr> to hold such items until the end of the function. This is the minimally-invasive fix. If we were to delete the items right after removeChild(), we might be changing the test, and if we deleted them only at the end of the function, we'd still be leaking them on a failed QCOMPARE(). Amends 1d799e91082092821a04885bd9d069febefc37da. This doesn't completely fix tst_QAbstractItemView; it still suffers from the QScroller leak, QTBUG-135055. Pick-to: 6.9 6.8 6.5 Task-number: QTBUG-135055 Change-Id: I2d3c661d5331ae33bb945f850fccdaa934f7a2dd Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
This commit is contained in:
parent
3c7719f2c2
commit
9ea9818eeb
@ -32,6 +32,9 @@
|
||||
#include <private/qabstractitemview_p.h>
|
||||
#include <QtWidgets/private/qapplication_p.h>
|
||||
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
|
||||
Q_DECLARE_METATYPE(Qt::ItemFlags);
|
||||
|
||||
using namespace QTestPrivate;
|
||||
@ -1629,6 +1632,7 @@ void tst_QAbstractItemView::testDelegateDestroyEditor()
|
||||
|
||||
void tst_QAbstractItemView::testDelegateDestroyEditorChild()
|
||||
{
|
||||
std::vector<std::unique_ptr<QTreeWidgetItem>> reaper;
|
||||
QTreeWidget tree;
|
||||
MyAbstractItemDelegate delegate;
|
||||
tree.setItemDelegate(&delegate);
|
||||
@ -1644,8 +1648,10 @@ void tst_QAbstractItemView::testDelegateDestroyEditorChild()
|
||||
tree.openPersistentEditor(levelTwo2);
|
||||
QCOMPARE(delegate.virtualCtorCallCount, 4);
|
||||
levelOne1->removeChild(levelTwo1);
|
||||
reaper.emplace_back(levelTwo1);
|
||||
QCOMPARE(delegate.virtualDtorCallCount, 1);
|
||||
topLevel->removeChild(levelOne2);
|
||||
reaper.emplace_back(levelOne2);
|
||||
QCOMPARE(delegate.virtualDtorCallCount, 3);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user