Commit 9a269a14 authored by Ronan Abhamon's avatar Ronan Abhamon

fix(src/components/contacts/ContactsListModel): set parent of contacts (avoid leaks)

parent e66f46f3
...@@ -30,7 +30,7 @@ using namespace std; ...@@ -30,7 +30,7 @@ using namespace std;
// ============================================================================= // =============================================================================
ContactModel::ContactModel (shared_ptr<linphone::Friend> linphone_friend) { ContactModel::ContactModel (QObject *parent, shared_ptr<linphone::Friend> linphone_friend) : QObject(parent) {
m_linphone_friend = linphone_friend; m_linphone_friend = linphone_friend;
m_vcard = make_shared<VcardModel>(linphone_friend->getVcard()); m_vcard = make_shared<VcardModel>(linphone_friend->getVcard());
...@@ -38,7 +38,7 @@ ContactModel::ContactModel (shared_ptr<linphone::Friend> linphone_friend) { ...@@ -38,7 +38,7 @@ ContactModel::ContactModel (shared_ptr<linphone::Friend> linphone_friend) {
m_linphone_friend->setData("contact-model", *this); m_linphone_friend->setData("contact-model", *this);
} }
ContactModel::ContactModel (VcardModel *vcard) { ContactModel::ContactModel (QObject *parent, VcardModel *vcard) : QObject(parent) {
Q_ASSERT(vcard != nullptr); Q_ASSERT(vcard != nullptr);
QQmlEngine *engine = App::getInstance()->getEngine(); QQmlEngine *engine = App::getInstance()->getEngine();
......
...@@ -40,8 +40,8 @@ class ContactModel : public QObject { ...@@ -40,8 +40,8 @@ class ContactModel : public QObject {
friend class SmartSearchBarModel; friend class SmartSearchBarModel;
public: public:
ContactModel (std::shared_ptr<linphone::Friend> linphone_friend); ContactModel (QObject *parent, std::shared_ptr<linphone::Friend> linphone_friend);
ContactModel (VcardModel *vcard); ContactModel (QObject *parent, VcardModel *vcard);
~ContactModel () = default; ~ContactModel () = default;
std::shared_ptr<VcardModel> getVcardModel () const { std::shared_ptr<VcardModel> getVcardModel () const {
......
...@@ -37,13 +37,11 @@ ContactsListModel::ContactsListModel (QObject *parent) : QAbstractListModel(pare ...@@ -37,13 +37,11 @@ ContactsListModel::ContactsListModel (QObject *parent) : QAbstractListModel(pare
// Init contacts with linphone friends list. // Init contacts with linphone friends list.
for (const auto &friend_ : m_linphone_friends->getFriends()) { for (const auto &friend_ : m_linphone_friends->getFriends()) {
ContactModel *contact = new ContactModel(friend_); ContactModel *contact = new ContactModel(this, friend_);
// See: http://doc.qt.io/qt-5/qtqml-cppintegration-data.html#data-ownership // See: http://doc.qt.io/qt-5/qtqml-cppintegration-data.html#data-ownership
// The returned value must have a explicit parent or a QQmlEngine::CppOwnership. // The returned value must have a explicit parent or a QQmlEngine::CppOwnership.
App::getInstance()->getEngine()->setObjectOwnership( App::getInstance()->getEngine()->setObjectOwnership(contact, QQmlEngine::CppOwnership);
contact, QQmlEngine::CppOwnership
);
addContact(contact); addContact(contact);
} }
...@@ -100,7 +98,7 @@ bool ContactsListModel::removeRows (int row, int count, const QModelIndex &paren ...@@ -100,7 +98,7 @@ bool ContactsListModel::removeRows (int row, int count, const QModelIndex &paren
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
ContactModel *ContactsListModel::addContact (VcardModel *vcard) { ContactModel *ContactsListModel::addContact (VcardModel *vcard) {
ContactModel *contact = new ContactModel(vcard); ContactModel *contact = new ContactModel(this, vcard);
App::getInstance()->getEngine()->setObjectOwnership(contact, QQmlEngine::CppOwnership); App::getInstance()->getEngine()->setObjectOwnership(contact, QQmlEngine::CppOwnership);
qInfo() << "Add contact:" << contact; qInfo() << "Add contact:" << contact;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment