From 8660373b0c11f83f796b526650916a1d69afbc60 Mon Sep 17 00:00:00 2001 From: Ming Rui Zhang <mingrui.zhang@savoirfairelinux.com> Date: Fri, 21 May 2021 09:53:40 -0400 Subject: [PATCH] contactadapter: fix SelectableProxyModel ownership Currently the ownership of SelectableProxyModel instance is assumed by QML engine, but we will use the following rule to avoid that. QML engine respects the normal QObject parent ownership semantics of Qt C++ objects, and will never delete a QObject instance which has a parent. https: //doc.qt.io/qt-5/qtqml-cppintegration-data.html Change-Id: Ifa37d14b8d74bfce050b0dee2949b42a7f784d3a --- src/contactadapter.cpp | 2 +- src/contactadapter.h | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/contactadapter.cpp b/src/contactadapter.cpp index fd8f6c4da..7c08440fa 100644 --- a/src/contactadapter.cpp +++ b/src/contactadapter.cpp @@ -25,7 +25,7 @@ ContactAdapter::ContactAdapter(LRCInstance* instance, QObject* parent) : QmlAdapterBase(instance, parent) { - selectableProxyModel_.reset(new SelectableProxyModel(smartListModel_.get())); + selectableProxyModel_.reset(new SelectableProxyModel(this)); } QVariant diff --git a/src/contactadapter.h b/src/contactadapter.h index bb958c003..6713bac54 100644 --- a/src/contactadapter.h +++ b/src/contactadapter.h @@ -44,10 +44,9 @@ class SelectableProxyModel final : public QSortFilterProxyModel public: using FilterPredicate = std::function<bool(const QModelIndex&, const QRegExp&)>; - explicit SelectableProxyModel(QAbstractListModel* parent = nullptr) + explicit SelectableProxyModel(QObject* parent = nullptr) : QSortFilterProxyModel(parent) { - setSourceModel(parent); setSortRole(ConversationList::Role::LastInteractionTimeStamp); sort(0, Qt::DescendingOrder); setFilterCaseSensitivity(Qt::CaseSensitivity::CaseInsensitive); -- GitLab